<? include 'dbcommon.php'; ?>
<?

class congty {

    public $id;
    public $ten;
    public $diachi;
    public $dienthoai;
    public $fax;
    public $sotaikhoan;
    public $tennganhang;
    public $masothue;
    public $ghichu;
    public $nhasanxuat;
    public $khachhang;
    public $isdeleted;

}

class congtydb {

    public static function insert(&$entity) {
        $db = new dbhelper();
        $query = "          INSERT INTO CongTy ( Ten , DiaChi , DienThoai , Fax , SoTaiKhoan , TenNganHang , MaSoThue , GhiChu , NhaSanXuat , KhachHang ,  IsDeleted) VALUES ( #Ten#, #DiaChi#, #DienThoai#, #Fax#, #SoTaiKhoan#, #TenNganHang#, #MaSoThue#, #GhiChu#, #NhaSanXuat#, #KhachHang#, #IsDeleted#)";
        $db->setQuery($query);
        $db->set_string_params("Ten", $entity->ten);
        $db->set_string_params("DiaChi", $entity->diachi);
        $db->set_string_params("DienThoai", $entity->dienthoai);
        $db->set_string_params("Fax", $entity->fax);
        $db->set_string_params("SoTaiKhoan", $entity->sotaikhoan);
        $db->set_string_params("TenNganHang", $entity->tennganhang);
        $db->set_string_params("MaSoThue", $entity->masothue);
        $db->set_string_params("GhiChu", $entity->ghichu);
        $db->set_string_params("NhaSanXuat", $entity->nhasanxuat);
        $db->set_string_params("KhachHang", $entity->khachhang);
        $db->set_string_params("IsDeleted", $entity->isdeleted);
        return $db->excute();
    }

    public static function update(&$entity) {
        $db = new dbhelper();
        $query = "UPDATE CongTy SET Ten = #Ten#, DiaChi = #DiaChi#, DienThoai = #DienThoai#, Fax = #Fax#, SoTaiKhoan = #SoTaiKhoan#, TenNganHang = #TenNganHang#, MaSoThue = #MaSoThue#, GhiChu = #GhiChu#, NhaSanXuat = #NhaSanXuat#, KhachHang = #KhachHang#, IsDeleted = #IsDeleted# WHERE Id = #Id#";
        $db->setQuery($query);
        $db->set_string_params("Id", $entity->id);
        $db->set_string_params("Ten", $entity->ten);
        $db->set_string_params("DiaChi", $entity->diachi);
        $db->set_string_params("DienThoai", $entity->dienthoai);
        $db->set_string_params("Fax", $entity->fax);
        $db->set_string_params("SoTaiKhoan", $entity->sotaikhoan);
        $db->set_string_params("TenNganHang", $entity->tennganhang);
        $db->set_string_params("MaSoThue", $entity->masothue);
        $db->set_string_params("GhiChu", $entity->ghichu);
        $db->set_string_params("NhaSanXuat", $entity->nhasanxuat);
        $db->set_string_params("KhachHang", $entity->khachhang);
        $db->set_string_params("IsDeleted", $entity->isdeleted);
        return $db->excute();
    }

    public static function get_all() {
        $db = new dbhelper();
        $query = "SELECT * FROM CongTy";
        $db->setQuery($query);
        $result = $db->excute();
        $entity_arr = array();
        $index = 0;
        while ($row = mysql_fetch_array($result)) {
            $entity = new congty();
            $entity->id = $row['Id'];
            $entity->ten = $row['Ten'];
            $entity->diachi = $row['DiaChi'];
            $entity->dienthoai = $row['DienThoai'];
            $entity->fax = $row['Fax'];
            $entity->sotaikhoan = $row['SoTaiKhoan'];
            $entity->tennganhang = $row['TenNganHang'];
            $entity->masothue = $row['MaSoThue'];
            $entity->ghichu = $row['GhiChu'];
            $entity->nhasanxuat = $row['NhaSanXuat'];
            $entity->khachhang = $row['KhachHang'];
            $entity->isdeleted = $row['IsDeleted'];
            $entity_arr[$index] = $entity;
            $index = $index + 1;
        }
        return $entity_arr;
    }

    public static function get(&$entity) {
        $db = new dbhelper();
        $query = "SELECT * FROM CongTy WHERE Id = #Id#";
        $db->setQuery($query);
        $db->set_string_params("Id", $entity->id);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new congty();
            $entity->id = $row['Id'];
            $entity->ten = $row['Ten'];
            $entity->diachi = $row['DiaChi'];
            $entity->dienthoai = $row['DienThoai'];
            $entity->fax = $row['Fax'];
            $entity->sotaikhoan = $row['SoTaiKhoan'];
            $entity->tennganhang = $row['TenNganHang'];
            $entity->masothue = $row['MaSoThue'];
            $entity->ghichu = $row['GhiChu'];
            $entity->nhasanxuat = $row['NhaSanXuat'];
            $entity->khachhang = $row['KhachHang'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_by_id($value) {
        $db = new dbhelper();
        $query = "SELECT * FROM CongTy WHERE id = #id#";
        $db->setQuery($query);
        $db->set_string_params($value);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new congty();
            $entity->id = $row['Id'];
            $entity->ten = $row['Ten'];
            $entity->diachi = $row['DiaChi'];
            $entity->dienthoai = $row['DienThoai'];
            $entity->fax = $row['Fax'];
            $entity->sotaikhoan = $row['SoTaiKhoan'];
            $entity->tennganhang = $row['TenNganHang'];
            $entity->masothue = $row['MaSoThue'];
            $entity->ghichu = $row['GhiChu'];
            $entity->nhasanxuat = $row['NhaSanXuat'];
            $entity->khachhang = $row['KhachHang'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_by_ten($value) {
        $db = new dbhelper();
        $query = "SELECT * FROM CongTy WHERE ten = #ten#";
        $db->setQuery($query);
        $db->set_string_params($value);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new congty();
            $entity->id = $row['Id'];
            $entity->ten = $row['Ten'];
            $entity->diachi = $row['DiaChi'];
            $entity->dienthoai = $row['DienThoai'];
            $entity->fax = $row['Fax'];
            $entity->sotaikhoan = $row['SoTaiKhoan'];
            $entity->tennganhang = $row['TenNganHang'];
            $entity->masothue = $row['MaSoThue'];
            $entity->ghichu = $row['GhiChu'];
            $entity->nhasanxuat = $row['NhaSanXuat'];
            $entity->khachhang = $row['KhachHang'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_by_diachi($value) {
        $db = new dbhelper();
        $query = "SELECT * FROM CongTy WHERE diachi = #diachi#";
        $db->setQuery($query);
        $db->set_string_params($value);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new congty();
            $entity->id = $row['Id'];
            $entity->ten = $row['Ten'];
            $entity->diachi = $row['DiaChi'];
            $entity->dienthoai = $row['DienThoai'];
            $entity->fax = $row['Fax'];
            $entity->sotaikhoan = $row['SoTaiKhoan'];
            $entity->tennganhang = $row['TenNganHang'];
            $entity->masothue = $row['MaSoThue'];
            $entity->ghichu = $row['GhiChu'];
            $entity->nhasanxuat = $row['NhaSanXuat'];
            $entity->khachhang = $row['KhachHang'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_by_dienthoai($value) {
        $db = new dbhelper();
        $query = "SELECT * FROM CongTy WHERE dienthoai = #dienthoai#";
        $db->setQuery($query);
        $db->set_string_params($value);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new congty();
            $entity->id = $row['Id'];
            $entity->ten = $row['Ten'];
            $entity->diachi = $row['DiaChi'];
            $entity->dienthoai = $row['DienThoai'];
            $entity->fax = $row['Fax'];
            $entity->sotaikhoan = $row['SoTaiKhoan'];
            $entity->tennganhang = $row['TenNganHang'];
            $entity->masothue = $row['MaSoThue'];
            $entity->ghichu = $row['GhiChu'];
            $entity->nhasanxuat = $row['NhaSanXuat'];
            $entity->khachhang = $row['KhachHang'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_by_fax($value) {
        $db = new dbhelper();
        $query = "SELECT * FROM CongTy WHERE fax = #fax#";
        $db->setQuery($query);
        $db->set_string_params($value);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new congty();
            $entity->id = $row['Id'];
            $entity->ten = $row['Ten'];
            $entity->diachi = $row['DiaChi'];
            $entity->dienthoai = $row['DienThoai'];
            $entity->fax = $row['Fax'];
            $entity->sotaikhoan = $row['SoTaiKhoan'];
            $entity->tennganhang = $row['TenNganHang'];
            $entity->masothue = $row['MaSoThue'];
            $entity->ghichu = $row['GhiChu'];
            $entity->nhasanxuat = $row['NhaSanXuat'];
            $entity->khachhang = $row['KhachHang'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_by_sotaikhoan($value) {
        $db = new dbhelper();
        $query = "SELECT * FROM CongTy WHERE sotaikhoan = #sotaikhoan#";
        $db->setQuery($query);
        $db->set_string_params($value);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new congty();
            $entity->id = $row['Id'];
            $entity->ten = $row['Ten'];
            $entity->diachi = $row['DiaChi'];
            $entity->dienthoai = $row['DienThoai'];
            $entity->fax = $row['Fax'];
            $entity->sotaikhoan = $row['SoTaiKhoan'];
            $entity->tennganhang = $row['TenNganHang'];
            $entity->masothue = $row['MaSoThue'];
            $entity->ghichu = $row['GhiChu'];
            $entity->nhasanxuat = $row['NhaSanXuat'];
            $entity->khachhang = $row['KhachHang'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_by_tennganhang($value) {
        $db = new dbhelper();
        $query = "SELECT * FROM CongTy WHERE tennganhang = #tennganhang#";
        $db->setQuery($query);
        $db->set_string_params($value);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new congty();
            $entity->id = $row['Id'];
            $entity->ten = $row['Ten'];
            $entity->diachi = $row['DiaChi'];
            $entity->dienthoai = $row['DienThoai'];
            $entity->fax = $row['Fax'];
            $entity->sotaikhoan = $row['SoTaiKhoan'];
            $entity->tennganhang = $row['TenNganHang'];
            $entity->masothue = $row['MaSoThue'];
            $entity->ghichu = $row['GhiChu'];
            $entity->nhasanxuat = $row['NhaSanXuat'];
            $entity->khachhang = $row['KhachHang'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_by_masothue($value) {
        $db = new dbhelper();
        $query = "SELECT * FROM CongTy WHERE masothue = #masothue#";
        $db->setQuery($query);
        $db->set_string_params($value);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new congty();
            $entity->id = $row['Id'];
            $entity->ten = $row['Ten'];
            $entity->diachi = $row['DiaChi'];
            $entity->dienthoai = $row['DienThoai'];
            $entity->fax = $row['Fax'];
            $entity->sotaikhoan = $row['SoTaiKhoan'];
            $entity->tennganhang = $row['TenNganHang'];
            $entity->masothue = $row['MaSoThue'];
            $entity->ghichu = $row['GhiChu'];
            $entity->nhasanxuat = $row['NhaSanXuat'];
            $entity->khachhang = $row['KhachHang'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_by_ghichu($value) {
        $db = new dbhelper();
        $query = "SELECT * FROM CongTy WHERE ghichu = #ghichu#";
        $db->setQuery($query);
        $db->set_string_params($value);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new congty();
            $entity->id = $row['Id'];
            $entity->ten = $row['Ten'];
            $entity->diachi = $row['DiaChi'];
            $entity->dienthoai = $row['DienThoai'];
            $entity->fax = $row['Fax'];
            $entity->sotaikhoan = $row['SoTaiKhoan'];
            $entity->tennganhang = $row['TenNganHang'];
            $entity->masothue = $row['MaSoThue'];
            $entity->ghichu = $row['GhiChu'];
            $entity->nhasanxuat = $row['NhaSanXuat'];
            $entity->khachhang = $row['KhachHang'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_by_nhasanxuat($value) {
        $db = new dbhelper();
        $query = "SELECT * FROM CongTy WHERE nhasanxuat = #nhasanxuat#";
        $db->setQuery($query);
        $db->set_string_params($value);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new congty();
            $entity->id = $row['Id'];
            $entity->ten = $row['Ten'];
            $entity->diachi = $row['DiaChi'];
            $entity->dienthoai = $row['DienThoai'];
            $entity->fax = $row['Fax'];
            $entity->sotaikhoan = $row['SoTaiKhoan'];
            $entity->tennganhang = $row['TenNganHang'];
            $entity->masothue = $row['MaSoThue'];
            $entity->ghichu = $row['GhiChu'];
            $entity->nhasanxuat = $row['NhaSanXuat'];
            $entity->khachhang = $row['KhachHang'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_by_khachhang($value) {
        $db = new dbhelper();
        $query = "SELECT * FROM CongTy WHERE khachhang = #khachhang#";
        $db->setQuery($query);
        $db->set_string_params($value);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new congty();
            $entity->id = $row['Id'];
            $entity->ten = $row['Ten'];
            $entity->diachi = $row['DiaChi'];
            $entity->dienthoai = $row['DienThoai'];
            $entity->fax = $row['Fax'];
            $entity->sotaikhoan = $row['SoTaiKhoan'];
            $entity->tennganhang = $row['TenNganHang'];
            $entity->masothue = $row['MaSoThue'];
            $entity->ghichu = $row['GhiChu'];
            $entity->nhasanxuat = $row['NhaSanXuat'];
            $entity->khachhang = $row['KhachHang'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_by_isdeleted($value) {
        $db = new dbhelper();
        $query = "SELECT * FROM CongTy WHERE isdeleted = #isdeleted#";
        $db->setQuery($query);
        $db->set_string_params($value);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new congty();
            $entity->id = $row['Id'];
            $entity->ten = $row['Ten'];
            $entity->diachi = $row['DiaChi'];
            $entity->dienthoai = $row['DienThoai'];
            $entity->fax = $row['Fax'];
            $entity->sotaikhoan = $row['SoTaiKhoan'];
            $entity->tennganhang = $row['TenNganHang'];
            $entity->masothue = $row['MaSoThue'];
            $entity->ghichu = $row['GhiChu'];
            $entity->nhasanxuat = $row['NhaSanXuat'];
            $entity->khachhang = $row['KhachHang'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_post_data() {
        $entity = new congty();
        $entity->id = $_POST["id"];
        $entity->ten = $_POST["ten"];
        $entity->diachi = $_POST["diachi"];
        $entity->dienthoai = $_POST["dienthoai"];
        $entity->fax = $_POST["fax"];
        $entity->sotaikhoan = $_POST["sotaikhoan"];
        $entity->tennganhang = $_POST["tennganhang"];
        $entity->masothue = $_POST["masothue"];
        $entity->ghichu = $_POST["ghichu"];
        $entity->nhasanxuat = $_POST["nhasanxuat"];
        $entity->khachhang = $_POST["khachhang"];
        $entity->isdeleted = $_POST["isdeleted"];
        return $entity;
    }

    public static function search($search_key) {
        $arr = explode(" ", trim($search_key));
        $search = "";
        for ($i = 0; $i < count($arr); $i++) {
            if ($search == "") {
                $search = $search . " WHERE ";
                $search = $search . "(";
                $search = $search . "id LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || ten LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || diachi LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || dienthoai LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || fax LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || sotaikhoan LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || tennganhang LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || masothue LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || ghichu LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || nhasanxuat LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || khachhang LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || isdeleted LIKE '%" . $arr[$i] . "%'";
                $search = $search . ")";
            } else {
                $search = $search . " AND ";
                $search = $search . "(";
                $search = $search . "id LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || ten LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || diachi LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || dienthoai LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || fax LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || sotaikhoan LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || tennganhang LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || masothue LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || ghichu LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || nhasanxuat LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || khachhang LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || isdeleted LIKE '%" . $arr[$i] . "%'";
                $search = $search . ")";
            }
            $db = new dbhelper();
            $query = "SELECT * FROM CongTy" . $search;
            $db->setQuery($query);
            $result = $db->excute();
            $entity_arr = array();
            $index = 0;
            while ($row = mysql_fetch_array($result)) {
                $entity = new congty();
                $entity->id = $row['Id'];
                $entity->ten = $row['Ten'];
                $entity->diachi = $row['DiaChi'];
                $entity->dienthoai = $row['DienThoai'];
                $entity->fax = $row['Fax'];
                $entity->sotaikhoan = $row['SoTaiKhoan'];
                $entity->tennganhang = $row['TenNganHang'];
                $entity->masothue = $row['MaSoThue'];
                $entity->ghichu = $row['GhiChu'];
                $entity->nhasanxuat = $row['NhaSanXuat'];
                $entity->khachhang = $row['KhachHang'];
                $entity->isdeleted = $row['IsDeleted'];
                $entity_arr[$index] = $entity;
                $index = $index + 1;
            }
            return $entity_arr;
        }
    }

}

?><?

class hoadon {

    public $id;
    public $ngaythang;
    public $loaihoadon;
    public $khachhangid;
    public $tenkhachhang;
    public $tendonvi;
    public $diachi;
    public $sodienthoai;
    public $sotaikhoan;
    public $tenxe;
    public $sokhung;
    public $somay;
    public $gia;
    public $tonghoadonso;
    public $tonghoadonchu;
    public $thuegtgt;
    public $phuongthucthanhtoan;
    public $laisuat;
    public $thoihan;
    public $tiendinhky;
    public $ghichu;
    public $isdeleted;

}

class hoadondb {

    public static function insert(&$entity) {
        $db = new dbhelper();
        $query = "                    INSERT INTO HoaDon ( NgayThang , LoaiHoaDon , KhachHangID , TenKhachHang , TenDonVi , DiaChi , SoDienThoai , SoTaiKhoan , TenXe , SoKhung , SoMay , Gia , TongHoaDonSo , TongHoaDonChu , ThueGTGT , PhuongThucThanhToan , LaiSuat , ThoiHan , TienDinhKy , GhiChu ,  IsDeleted) VALUES ( #NgayThang#, #LoaiHoaDon#, #KhachHangID#, #TenKhachHang#, #TenDonVi#, #DiaChi#, #SoDienThoai#, #SoTaiKhoan#, #TenXe#, #SoKhung#, #SoMay#, #Gia#, #TongHoaDonSo#, #TongHoaDonChu#, #ThueGTGT#, #PhuongThucThanhToan#, #LaiSuat#, #ThoiHan#, #TienDinhKy#, #GhiChu#, #IsDeleted#)";
        $db->setQuery($query);
        $db->set_string_params("NgayThang", date('Y-m-d H:i:s', strtotime($entity->ngaythang)));
        $db->set_string_params("LoaiHoaDon", $entity->loaihoadon);
        $db->set_string_params("KhachHangID", $entity->khachhangid);
        $db->set_string_params("TenKhachHang", $entity->tenkhachhang);
        $db->set_string_params("TenDonVi", $entity->tendonvi);
        $db->set_string_params("DiaChi", $entity->diachi);
        $db->set_string_params("SoDienThoai", $entity->sodienthoai);
        $db->set_string_params("SoTaiKhoan", $entity->sotaikhoan);
        $db->set_string_params("TenXe", $entity->tenxe);
        $db->set_string_params("SoKhung", $entity->sokhung);
        $db->set_string_params("SoMay", $entity->somay);
        $db->set_string_params("Gia", $entity->gia);
        $db->set_string_params("TongHoaDonSo", $entity->tonghoadonso);
        $db->set_string_params("TongHoaDonChu", $entity->tonghoadonchu);
        $db->set_string_params("ThueGTGT", $entity->thuegtgt);
        $db->set_string_params("PhuongThucThanhToan", $entity->phuongthucthanhtoan);
        $db->set_string_params("LaiSuat", $entity->laisuat);
        $db->set_string_params("ThoiHan", $entity->thoihan);
        $db->set_string_params("TienDinhKy", $entity->tiendinhky);
        $db->set_string_params("GhiChu", $entity->ghichu);
        $db->set_string_params("IsDeleted", $entity->isdeleted);
        return $db->excute();
    }

    public static function get_last_insert() {

        //SELECT ID FROM HoaDon WHERE IsDeleted = 'N' ORDER BY Id DESC LIMIT 1
        $db = new dbhelper();
        $query = "SELECT Id FROM HoaDon WHERE IsDeleted = 'N' ORDER BY Id DESC LIMIT 1;";
        $db->setQuery($query);
        //$db->set_string_params("Id", $entity->id);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            return $row['Id'];
        }
    }

    public static function update(&$entity) {
        $db = new dbhelper();
        $query = "UPDATE HoaDon SET NgayThang = #NgayThang#, LoaiHoaDon = #LoaiHoaDon#, KhachHangID = #KhachHangID#, TenKhachHang = #TenKhachHang#, TenDonVi = #TenDonVi#, DiaChi = #DiaChi#, SoDienThoai = #SoDienThoai#, SoTaiKhoan = #SoTaiKhoan#, TenXe = #TenXe#, SoKhung = #SoKhung#, SoMay = #SoMay#, Gia = #Gia#, TongHoaDonSo = #TongHoaDonSo#, TongHoaDonChu = #TongHoaDonChu#, ThueGTGT = #ThueGTGT#, PhuongThucThanhToan = #PhuongThucThanhToan#, LaiSuat = #LaiSuat#, ThoiHan = #ThoiHan#, TienDinhKy = #TienDinhKy#, GhiChu = #GhiChu#, IsDeleted = #IsDeleted# WHERE Id = #Id#";
        $db->setQuery($query);
        $db->set_string_params("Id", $entity->id);
        $db->set_string_params("NgayThang", $entity->ngaythang);
        $db->set_string_params("LoaiHoaDon", $entity->loaihoadon);
        $db->set_string_params("KhachHangID", $entity->khachhangid);
        $db->set_string_params("TenKhachHang", $entity->tenkhachhang);
        $db->set_string_params("TenDonVi", $entity->tendonvi);
        $db->set_string_params("DiaChi", $entity->diachi);
        $db->set_string_params("SoDienThoai", $entity->sodienthoai);
        $db->set_string_params("SoTaiKhoan", $entity->sotaikhoan);
        $db->set_string_params("TenXe", $entity->tenxe);
        $db->set_string_params("SoKhung", $entity->sokhung);
        $db->set_string_params("SoMay", $entity->somay);
        $db->set_string_params("Gia", $entity->gia);
        $db->set_string_params("TongHoaDonSo", $entity->tonghoadonso);
        $db->set_string_params("TongHoaDonChu", $entity->tonghoadonchu);
        $db->set_string_params("ThueGTGT", $entity->thuegtgt);
        $db->set_string_params("PhuongThucThanhToan", $entity->phuongthucthanhtoan);
        $db->set_string_params("LaiSuat", $entity->laisuat);
        $db->set_string_params("ThoiHan", $entity->thoihan);
        $db->set_string_params("TienDinhKy", $entity->tiendinhky);
        $db->set_string_params("GhiChu", $entity->ghichu);
        $db->set_string_params("IsDeleted", $entity->isdeleted);
        return $db->excute();
    }

    public static function get_all() {
        $db = new dbhelper();
        $query = "SELECT * FROM HoaDon";
        $db->setQuery($query);
        $result = $db->excute();
        $entity_arr = array();
        $index = 0;
        while ($row = mysql_fetch_array($result)) {
            $entity = new hoadon();
            $entity->id = $row['Id'];
            $entity->ngaythang = $row['NgayThang'];
            $entity->loaihoadon = $row['LoaiHoaDon'];
            $entity->khachhangid = $row['KhachHangID'];
            $entity->tenkhachhang = $row['TenKhachHang'];
            $entity->tendonvi = $row['TenDonVi'];
            $entity->diachi = $row['DiaChi'];
            $entity->sodienthoai = $row['SoDienThoai'];
            $entity->sotaikhoan = $row['SoTaiKhoan'];
            $entity->tenxe = $row['TenXe'];
            $entity->sokhung = $row['SoKhung'];
            $entity->somay = $row['SoMay'];
            $entity->gia = $row['Gia'];
            $entity->tonghoadonso = $row['TongHoaDonSo'];
            $entity->tonghoadonchu = $row['TongHoaDonChu'];
            $entity->thuegtgt = $row['ThueGTGT'];
            $entity->phuongthucthanhtoan = $row['PhuongThucThanhToan'];
            $entity->laisuat = $row['LaiSuat'];
            $entity->thoihan = $row['ThoiHan'];
            $entity->tiendinhky = $row['TienDinhKy'];
            $entity->ghichu = $row['GhiChu'];
            $entity->isdeleted = $row['IsDeleted'];
            $entity_arr[$index] = $entity;
            $index = $index + 1;
        }
        return $entity_arr;
    }

    public static function get(&$entity) {
        $db = new dbhelper();
        $query = "SELECT * FROM HoaDon WHERE Id = #Id#";
        $db->setQuery($query);
        $db->set_string_params("Id", $entity->id);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new hoadon();
            $entity->id = $row['Id'];
            $entity->ngaythang = $row['NgayThang'];
            $entity->loaihoadon = $row['LoaiHoaDon'];
            $entity->khachhangid = $row['KhachHangID'];
            $entity->tenkhachhang = $row['TenKhachHang'];
            $entity->tendonvi = $row['TenDonVi'];
            $entity->diachi = $row['DiaChi'];
            $entity->sodienthoai = $row['SoDienThoai'];
            $entity->sotaikhoan = $row['SoTaiKhoan'];
            $entity->tenxe = $row['TenXe'];
            $entity->sokhung = $row['SoKhung'];
            $entity->somay = $row['SoMay'];
            $entity->gia = $row['Gia'];
            $entity->tonghoadonso = $row['TongHoaDonSo'];
            $entity->tonghoadonchu = $row['TongHoaDonChu'];
            $entity->thuegtgt = $row['ThueGTGT'];
            $entity->phuongthucthanhtoan = $row['PhuongThucThanhToan'];
            $entity->laisuat = $row['LaiSuat'];
            $entity->thoihan = $row['ThoiHan'];
            $entity->tiendinhky = $row['TienDinhKy'];
            $entity->ghichu = $row['GhiChu'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_by_id($value) {
        $db = new dbhelper();
        $query = "SELECT * FROM HoaDon WHERE id = #id#";
        $db->setQuery($query);
        $db->set_int_params("id", $value);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new hoadon();
            $entity->id = $row['Id'];
            $entity->ngaythang = $row['NgayThang'];
            $entity->loaihoadon = $row['LoaiHoaDon'];
            $entity->khachhangid = $row['KhachHangID'];
            $entity->tenkhachhang = $row['TenKhachHang'];
            $entity->tendonvi = $row['TenDonVi'];
            $entity->diachi = $row['DiaChi'];
            $entity->sodienthoai = $row['SoDienThoai'];
            $entity->sotaikhoan = $row['SoTaiKhoan'];
            $entity->tenxe = $row['TenXe'];
            $entity->sokhung = $row['SoKhung'];
            $entity->somay = $row['SoMay'];
            $entity->gia = $row['Gia'];
            $entity->tonghoadonso = $row['TongHoaDonSo'];
            $entity->tonghoadonchu = $row['TongHoaDonChu'];
            $entity->thuegtgt = $row['ThueGTGT'];
            $entity->phuongthucthanhtoan = $row['PhuongThucThanhToan'];
            $entity->laisuat = $row['LaiSuat'];
            $entity->thoihan = $row['ThoiHan'];
            $entity->tiendinhky = $row['TienDinhKy'];
            $entity->ghichu = $row['GhiChu'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_by_ngaythang($value) {
        $db = new dbhelper();
        $query = "SELECT * FROM HoaDon WHERE ngaythang = #ngaythang#";
        $db->setQuery($query);
        $db->set_string_params($value);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new hoadon();
            $entity->id = $row['Id'];
            $entity->ngaythang = $row['NgayThang'];
            $entity->loaihoadon = $row['LoaiHoaDon'];
            $entity->khachhangid = $row['KhachHangID'];
            $entity->tenkhachhang = $row['TenKhachHang'];
            $entity->tendonvi = $row['TenDonVi'];
            $entity->diachi = $row['DiaChi'];
            $entity->sodienthoai = $row['SoDienThoai'];
            $entity->sotaikhoan = $row['SoTaiKhoan'];
            $entity->tenxe = $row['TenXe'];
            $entity->sokhung = $row['SoKhung'];
            $entity->somay = $row['SoMay'];
            $entity->gia = $row['Gia'];
            $entity->tonghoadonso = $row['TongHoaDonSo'];
            $entity->tonghoadonchu = $row['TongHoaDonChu'];
            $entity->thuegtgt = $row['ThueGTGT'];
            $entity->phuongthucthanhtoan = $row['PhuongThucThanhToan'];
            $entity->laisuat = $row['LaiSuat'];
            $entity->thoihan = $row['ThoiHan'];
            $entity->tiendinhky = $row['TienDinhKy'];
            $entity->ghichu = $row['GhiChu'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_by_loaihoadon($value) {
        $db = new dbhelper();
        $query = "SELECT * FROM HoaDon WHERE loaihoadon = #loaihoadon#";
        $db->setQuery($query);
        $db->set_string_params($value);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new hoadon();
            $entity->id = $row['Id'];
            $entity->ngaythang = $row['NgayThang'];
            $entity->loaihoadon = $row['LoaiHoaDon'];
            $entity->khachhangid = $row['KhachHangID'];
            $entity->tenkhachhang = $row['TenKhachHang'];
            $entity->tendonvi = $row['TenDonVi'];
            $entity->diachi = $row['DiaChi'];
            $entity->sodienthoai = $row['SoDienThoai'];
            $entity->sotaikhoan = $row['SoTaiKhoan'];
            $entity->tenxe = $row['TenXe'];
            $entity->sokhung = $row['SoKhung'];
            $entity->somay = $row['SoMay'];
            $entity->gia = $row['Gia'];
            $entity->tonghoadonso = $row['TongHoaDonSo'];
            $entity->tonghoadonchu = $row['TongHoaDonChu'];
            $entity->thuegtgt = $row['ThueGTGT'];
            $entity->phuongthucthanhtoan = $row['PhuongThucThanhToan'];
            $entity->laisuat = $row['LaiSuat'];
            $entity->thoihan = $row['ThoiHan'];
            $entity->tiendinhky = $row['TienDinhKy'];
            $entity->ghichu = $row['GhiChu'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_by_khachhangid($value) {
        $db = new dbhelper();
        $query = "SELECT * FROM HoaDon WHERE khachhangid = #khachhangid#";
        $db->setQuery($query);
        $db->set_string_params($value);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new hoadon();
            $entity->id = $row['Id'];
            $entity->ngaythang = $row['NgayThang'];
            $entity->loaihoadon = $row['LoaiHoaDon'];
            $entity->khachhangid = $row['KhachHangID'];
            $entity->tenkhachhang = $row['TenKhachHang'];
            $entity->tendonvi = $row['TenDonVi'];
            $entity->diachi = $row['DiaChi'];
            $entity->sodienthoai = $row['SoDienThoai'];
            $entity->sotaikhoan = $row['SoTaiKhoan'];
            $entity->tenxe = $row['TenXe'];
            $entity->sokhung = $row['SoKhung'];
            $entity->somay = $row['SoMay'];
            $entity->gia = $row['Gia'];
            $entity->tonghoadonso = $row['TongHoaDonSo'];
            $entity->tonghoadonchu = $row['TongHoaDonChu'];
            $entity->thuegtgt = $row['ThueGTGT'];
            $entity->phuongthucthanhtoan = $row['PhuongThucThanhToan'];
            $entity->laisuat = $row['LaiSuat'];
            $entity->thoihan = $row['ThoiHan'];
            $entity->tiendinhky = $row['TienDinhKy'];
            $entity->ghichu = $row['GhiChu'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_by_tenkhachhang($value) {
        $db = new dbhelper();
        $query = "SELECT * FROM HoaDon WHERE tenkhachhang = #tenkhachhang#";
        $db->setQuery($query);
        $db->set_string_params($value);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new hoadon();
            $entity->id = $row['Id'];
            $entity->ngaythang = $row['NgayThang'];
            $entity->loaihoadon = $row['LoaiHoaDon'];
            $entity->khachhangid = $row['KhachHangID'];
            $entity->tenkhachhang = $row['TenKhachHang'];
            $entity->tendonvi = $row['TenDonVi'];
            $entity->diachi = $row['DiaChi'];
            $entity->sodienthoai = $row['SoDienThoai'];
            $entity->sotaikhoan = $row['SoTaiKhoan'];
            $entity->tenxe = $row['TenXe'];
            $entity->sokhung = $row['SoKhung'];
            $entity->somay = $row['SoMay'];
            $entity->gia = $row['Gia'];
            $entity->tonghoadonso = $row['TongHoaDonSo'];
            $entity->tonghoadonchu = $row['TongHoaDonChu'];
            $entity->thuegtgt = $row['ThueGTGT'];
            $entity->phuongthucthanhtoan = $row['PhuongThucThanhToan'];
            $entity->laisuat = $row['LaiSuat'];
            $entity->thoihan = $row['ThoiHan'];
            $entity->tiendinhky = $row['TienDinhKy'];
            $entity->ghichu = $row['GhiChu'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_by_tendonvi($value) {
        $db = new dbhelper();
        $query = "SELECT * FROM HoaDon WHERE tendonvi = #tendonvi#";
        $db->setQuery($query);
        $db->set_string_params($value);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new hoadon();
            $entity->id = $row['Id'];
            $entity->ngaythang = $row['NgayThang'];
            $entity->loaihoadon = $row['LoaiHoaDon'];
            $entity->khachhangid = $row['KhachHangID'];
            $entity->tenkhachhang = $row['TenKhachHang'];
            $entity->tendonvi = $row['TenDonVi'];
            $entity->diachi = $row['DiaChi'];
            $entity->sodienthoai = $row['SoDienThoai'];
            $entity->sotaikhoan = $row['SoTaiKhoan'];
            $entity->tenxe = $row['TenXe'];
            $entity->sokhung = $row['SoKhung'];
            $entity->somay = $row['SoMay'];
            $entity->gia = $row['Gia'];
            $entity->tonghoadonso = $row['TongHoaDonSo'];
            $entity->tonghoadonchu = $row['TongHoaDonChu'];
            $entity->thuegtgt = $row['ThueGTGT'];
            $entity->phuongthucthanhtoan = $row['PhuongThucThanhToan'];
            $entity->laisuat = $row['LaiSuat'];
            $entity->thoihan = $row['ThoiHan'];
            $entity->tiendinhky = $row['TienDinhKy'];
            $entity->ghichu = $row['GhiChu'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_by_diachi($value) {
        $db = new dbhelper();
        $query = "SELECT * FROM HoaDon WHERE diachi = #diachi#";
        $db->setQuery($query);
        $db->set_string_params($value);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new hoadon();
            $entity->id = $row['Id'];
            $entity->ngaythang = $row['NgayThang'];
            $entity->loaihoadon = $row['LoaiHoaDon'];
            $entity->khachhangid = $row['KhachHangID'];
            $entity->tenkhachhang = $row['TenKhachHang'];
            $entity->tendonvi = $row['TenDonVi'];
            $entity->diachi = $row['DiaChi'];
            $entity->sodienthoai = $row['SoDienThoai'];
            $entity->sotaikhoan = $row['SoTaiKhoan'];
            $entity->tenxe = $row['TenXe'];
            $entity->sokhung = $row['SoKhung'];
            $entity->somay = $row['SoMay'];
            $entity->gia = $row['Gia'];
            $entity->tonghoadonso = $row['TongHoaDonSo'];
            $entity->tonghoadonchu = $row['TongHoaDonChu'];
            $entity->thuegtgt = $row['ThueGTGT'];
            $entity->phuongthucthanhtoan = $row['PhuongThucThanhToan'];
            $entity->laisuat = $row['LaiSuat'];
            $entity->thoihan = $row['ThoiHan'];
            $entity->tiendinhky = $row['TienDinhKy'];
            $entity->ghichu = $row['GhiChu'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_by_sodienthoai($value) {
        $db = new dbhelper();
        $query = "SELECT * FROM HoaDon WHERE sodienthoai = #sodienthoai#";
        $db->setQuery($query);
        $db->set_string_params($value);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new hoadon();
            $entity->id = $row['Id'];
            $entity->ngaythang = $row['NgayThang'];
            $entity->loaihoadon = $row['LoaiHoaDon'];
            $entity->khachhangid = $row['KhachHangID'];
            $entity->tenkhachhang = $row['TenKhachHang'];
            $entity->tendonvi = $row['TenDonVi'];
            $entity->diachi = $row['DiaChi'];
            $entity->sodienthoai = $row['SoDienThoai'];
            $entity->sotaikhoan = $row['SoTaiKhoan'];
            $entity->tenxe = $row['TenXe'];
            $entity->sokhung = $row['SoKhung'];
            $entity->somay = $row['SoMay'];
            $entity->gia = $row['Gia'];
            $entity->tonghoadonso = $row['TongHoaDonSo'];
            $entity->tonghoadonchu = $row['TongHoaDonChu'];
            $entity->thuegtgt = $row['ThueGTGT'];
            $entity->phuongthucthanhtoan = $row['PhuongThucThanhToan'];
            $entity->laisuat = $row['LaiSuat'];
            $entity->thoihan = $row['ThoiHan'];
            $entity->tiendinhky = $row['TienDinhKy'];
            $entity->ghichu = $row['GhiChu'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_by_sotaikhoan($value) {
        $db = new dbhelper();
        $query = "SELECT * FROM HoaDon WHERE sotaikhoan = #sotaikhoan#";
        $db->setQuery($query);
        $db->set_string_params($value);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new hoadon();
            $entity->id = $row['Id'];
            $entity->ngaythang = $row['NgayThang'];
            $entity->loaihoadon = $row['LoaiHoaDon'];
            $entity->khachhangid = $row['KhachHangID'];
            $entity->tenkhachhang = $row['TenKhachHang'];
            $entity->tendonvi = $row['TenDonVi'];
            $entity->diachi = $row['DiaChi'];
            $entity->sodienthoai = $row['SoDienThoai'];
            $entity->sotaikhoan = $row['SoTaiKhoan'];
            $entity->tenxe = $row['TenXe'];
            $entity->sokhung = $row['SoKhung'];
            $entity->somay = $row['SoMay'];
            $entity->gia = $row['Gia'];
            $entity->tonghoadonso = $row['TongHoaDonSo'];
            $entity->tonghoadonchu = $row['TongHoaDonChu'];
            $entity->thuegtgt = $row['ThueGTGT'];
            $entity->phuongthucthanhtoan = $row['PhuongThucThanhToan'];
            $entity->laisuat = $row['LaiSuat'];
            $entity->thoihan = $row['ThoiHan'];
            $entity->tiendinhky = $row['TienDinhKy'];
            $entity->ghichu = $row['GhiChu'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_by_tenxe($value) {
        $db = new dbhelper();
        $query = "SELECT * FROM HoaDon WHERE tenxe = #tenxe#";
        $db->setQuery($query);
        $db->set_string_params($value);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new hoadon();
            $entity->id = $row['Id'];
            $entity->ngaythang = $row['NgayThang'];
            $entity->loaihoadon = $row['LoaiHoaDon'];
            $entity->khachhangid = $row['KhachHangID'];
            $entity->tenkhachhang = $row['TenKhachHang'];
            $entity->tendonvi = $row['TenDonVi'];
            $entity->diachi = $row['DiaChi'];
            $entity->sodienthoai = $row['SoDienThoai'];
            $entity->sotaikhoan = $row['SoTaiKhoan'];
            $entity->tenxe = $row['TenXe'];
            $entity->sokhung = $row['SoKhung'];
            $entity->somay = $row['SoMay'];
            $entity->gia = $row['Gia'];
            $entity->tonghoadonso = $row['TongHoaDonSo'];
            $entity->tonghoadonchu = $row['TongHoaDonChu'];
            $entity->thuegtgt = $row['ThueGTGT'];
            $entity->phuongthucthanhtoan = $row['PhuongThucThanhToan'];
            $entity->laisuat = $row['LaiSuat'];
            $entity->thoihan = $row['ThoiHan'];
            $entity->tiendinhky = $row['TienDinhKy'];
            $entity->ghichu = $row['GhiChu'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_by_sokhung($value) {
        $db = new dbhelper();
        $query = "SELECT * FROM HoaDon WHERE sokhung = #sokhung#";
        $db->setQuery($query);
        $db->set_string_params($value);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new hoadon();
            $entity->id = $row['Id'];
            $entity->ngaythang = $row['NgayThang'];
            $entity->loaihoadon = $row['LoaiHoaDon'];
            $entity->khachhangid = $row['KhachHangID'];
            $entity->tenkhachhang = $row['TenKhachHang'];
            $entity->tendonvi = $row['TenDonVi'];
            $entity->diachi = $row['DiaChi'];
            $entity->sodienthoai = $row['SoDienThoai'];
            $entity->sotaikhoan = $row['SoTaiKhoan'];
            $entity->tenxe = $row['TenXe'];
            $entity->sokhung = $row['SoKhung'];
            $entity->somay = $row['SoMay'];
            $entity->gia = $row['Gia'];
            $entity->tonghoadonso = $row['TongHoaDonSo'];
            $entity->tonghoadonchu = $row['TongHoaDonChu'];
            $entity->thuegtgt = $row['ThueGTGT'];
            $entity->phuongthucthanhtoan = $row['PhuongThucThanhToan'];
            $entity->laisuat = $row['LaiSuat'];
            $entity->thoihan = $row['ThoiHan'];
            $entity->tiendinhky = $row['TienDinhKy'];
            $entity->ghichu = $row['GhiChu'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_by_somay($value) {
        $db = new dbhelper();
        $query = "SELECT * FROM HoaDon WHERE somay = #somay#";
        $db->setQuery($query);
        $db->set_string_params($value);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new hoadon();
            $entity->id = $row['Id'];
            $entity->ngaythang = $row['NgayThang'];
            $entity->loaihoadon = $row['LoaiHoaDon'];
            $entity->khachhangid = $row['KhachHangID'];
            $entity->tenkhachhang = $row['TenKhachHang'];
            $entity->tendonvi = $row['TenDonVi'];
            $entity->diachi = $row['DiaChi'];
            $entity->sodienthoai = $row['SoDienThoai'];
            $entity->sotaikhoan = $row['SoTaiKhoan'];
            $entity->tenxe = $row['TenXe'];
            $entity->sokhung = $row['SoKhung'];
            $entity->somay = $row['SoMay'];
            $entity->gia = $row['Gia'];
            $entity->tonghoadonso = $row['TongHoaDonSo'];
            $entity->tonghoadonchu = $row['TongHoaDonChu'];
            $entity->thuegtgt = $row['ThueGTGT'];
            $entity->phuongthucthanhtoan = $row['PhuongThucThanhToan'];
            $entity->laisuat = $row['LaiSuat'];
            $entity->thoihan = $row['ThoiHan'];
            $entity->tiendinhky = $row['TienDinhKy'];
            $entity->ghichu = $row['GhiChu'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_by_gia($value) {
        $db = new dbhelper();
        $query = "SELECT * FROM HoaDon WHERE gia = #gia#";
        $db->setQuery($query);
        $db->set_string_params($value);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new hoadon();
            $entity->id = $row['Id'];
            $entity->ngaythang = $row['NgayThang'];
            $entity->loaihoadon = $row['LoaiHoaDon'];
            $entity->khachhangid = $row['KhachHangID'];
            $entity->tenkhachhang = $row['TenKhachHang'];
            $entity->tendonvi = $row['TenDonVi'];
            $entity->diachi = $row['DiaChi'];
            $entity->sodienthoai = $row['SoDienThoai'];
            $entity->sotaikhoan = $row['SoTaiKhoan'];
            $entity->tenxe = $row['TenXe'];
            $entity->sokhung = $row['SoKhung'];
            $entity->somay = $row['SoMay'];
            $entity->gia = $row['Gia'];
            $entity->tonghoadonso = $row['TongHoaDonSo'];
            $entity->tonghoadonchu = $row['TongHoaDonChu'];
            $entity->thuegtgt = $row['ThueGTGT'];
            $entity->phuongthucthanhtoan = $row['PhuongThucThanhToan'];
            $entity->laisuat = $row['LaiSuat'];
            $entity->thoihan = $row['ThoiHan'];
            $entity->tiendinhky = $row['TienDinhKy'];
            $entity->ghichu = $row['GhiChu'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_by_tonghoadonso($value) {
        $db = new dbhelper();
        $query = "SELECT * FROM HoaDon WHERE tonghoadonso = #tonghoadonso#";
        $db->setQuery($query);
        $db->set_string_params($value);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new hoadon();
            $entity->id = $row['Id'];
            $entity->ngaythang = $row['NgayThang'];
            $entity->loaihoadon = $row['LoaiHoaDon'];
            $entity->khachhangid = $row['KhachHangID'];
            $entity->tenkhachhang = $row['TenKhachHang'];
            $entity->tendonvi = $row['TenDonVi'];
            $entity->diachi = $row['DiaChi'];
            $entity->sodienthoai = $row['SoDienThoai'];
            $entity->sotaikhoan = $row['SoTaiKhoan'];
            $entity->tenxe = $row['TenXe'];
            $entity->sokhung = $row['SoKhung'];
            $entity->somay = $row['SoMay'];
            $entity->gia = $row['Gia'];
            $entity->tonghoadonso = $row['TongHoaDonSo'];
            $entity->tonghoadonchu = $row['TongHoaDonChu'];
            $entity->thuegtgt = $row['ThueGTGT'];
            $entity->phuongthucthanhtoan = $row['PhuongThucThanhToan'];
            $entity->laisuat = $row['LaiSuat'];
            $entity->thoihan = $row['ThoiHan'];
            $entity->tiendinhky = $row['TienDinhKy'];
            $entity->ghichu = $row['GhiChu'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_by_tonghoadonchu($value) {
        $db = new dbhelper();
        $query = "SELECT * FROM HoaDon WHERE tonghoadonchu = #tonghoadonchu#";
        $db->setQuery($query);
        $db->set_string_params($value);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new hoadon();
            $entity->id = $row['Id'];
            $entity->ngaythang = $row['NgayThang'];
            $entity->loaihoadon = $row['LoaiHoaDon'];
            $entity->khachhangid = $row['KhachHangID'];
            $entity->tenkhachhang = $row['TenKhachHang'];
            $entity->tendonvi = $row['TenDonVi'];
            $entity->diachi = $row['DiaChi'];
            $entity->sodienthoai = $row['SoDienThoai'];
            $entity->sotaikhoan = $row['SoTaiKhoan'];
            $entity->tenxe = $row['TenXe'];
            $entity->sokhung = $row['SoKhung'];
            $entity->somay = $row['SoMay'];
            $entity->gia = $row['Gia'];
            $entity->tonghoadonso = $row['TongHoaDonSo'];
            $entity->tonghoadonchu = $row['TongHoaDonChu'];
            $entity->thuegtgt = $row['ThueGTGT'];
            $entity->phuongthucthanhtoan = $row['PhuongThucThanhToan'];
            $entity->laisuat = $row['LaiSuat'];
            $entity->thoihan = $row['ThoiHan'];
            $entity->tiendinhky = $row['TienDinhKy'];
            $entity->ghichu = $row['GhiChu'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_by_thuegtgt($value) {
        $db = new dbhelper();
        $query = "SELECT * FROM HoaDon WHERE thuegtgt = #thuegtgt#";
        $db->setQuery($query);
        $db->set_string_params($value);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new hoadon();
            $entity->id = $row['Id'];
            $entity->ngaythang = $row['NgayThang'];
            $entity->loaihoadon = $row['LoaiHoaDon'];
            $entity->khachhangid = $row['KhachHangID'];
            $entity->tenkhachhang = $row['TenKhachHang'];
            $entity->tendonvi = $row['TenDonVi'];
            $entity->diachi = $row['DiaChi'];
            $entity->sodienthoai = $row['SoDienThoai'];
            $entity->sotaikhoan = $row['SoTaiKhoan'];
            $entity->tenxe = $row['TenXe'];
            $entity->sokhung = $row['SoKhung'];
            $entity->somay = $row['SoMay'];
            $entity->gia = $row['Gia'];
            $entity->tonghoadonso = $row['TongHoaDonSo'];
            $entity->tonghoadonchu = $row['TongHoaDonChu'];
            $entity->thuegtgt = $row['ThueGTGT'];
            $entity->phuongthucthanhtoan = $row['PhuongThucThanhToan'];
            $entity->laisuat = $row['LaiSuat'];
            $entity->thoihan = $row['ThoiHan'];
            $entity->tiendinhky = $row['TienDinhKy'];
            $entity->ghichu = $row['GhiChu'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_by_phuongthucthanhtoan($value) {
        $db = new dbhelper();
        $query = "SELECT * FROM HoaDon WHERE phuongthucthanhtoan = #phuongthucthanhtoan#";
        $db->setQuery($query);
        $db->set_string_params($value);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new hoadon();
            $entity->id = $row['Id'];
            $entity->ngaythang = $row['NgayThang'];
            $entity->loaihoadon = $row['LoaiHoaDon'];
            $entity->khachhangid = $row['KhachHangID'];
            $entity->tenkhachhang = $row['TenKhachHang'];
            $entity->tendonvi = $row['TenDonVi'];
            $entity->diachi = $row['DiaChi'];
            $entity->sodienthoai = $row['SoDienThoai'];
            $entity->sotaikhoan = $row['SoTaiKhoan'];
            $entity->tenxe = $row['TenXe'];
            $entity->sokhung = $row['SoKhung'];
            $entity->somay = $row['SoMay'];
            $entity->gia = $row['Gia'];
            $entity->tonghoadonso = $row['TongHoaDonSo'];
            $entity->tonghoadonchu = $row['TongHoaDonChu'];
            $entity->thuegtgt = $row['ThueGTGT'];
            $entity->phuongthucthanhtoan = $row['PhuongThucThanhToan'];
            $entity->laisuat = $row['LaiSuat'];
            $entity->thoihan = $row['ThoiHan'];
            $entity->tiendinhky = $row['TienDinhKy'];
            $entity->ghichu = $row['GhiChu'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_by_laisuat($value) {
        $db = new dbhelper();
        $query = "SELECT * FROM HoaDon WHERE laisuat = #laisuat#";
        $db->setQuery($query);
        $db->set_string_params($value);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new hoadon();
            $entity->id = $row['Id'];
            $entity->ngaythang = $row['NgayThang'];
            $entity->loaihoadon = $row['LoaiHoaDon'];
            $entity->khachhangid = $row['KhachHangID'];
            $entity->tenkhachhang = $row['TenKhachHang'];
            $entity->tendonvi = $row['TenDonVi'];
            $entity->diachi = $row['DiaChi'];
            $entity->sodienthoai = $row['SoDienThoai'];
            $entity->sotaikhoan = $row['SoTaiKhoan'];
            $entity->tenxe = $row['TenXe'];
            $entity->sokhung = $row['SoKhung'];
            $entity->somay = $row['SoMay'];
            $entity->gia = $row['Gia'];
            $entity->tonghoadonso = $row['TongHoaDonSo'];
            $entity->tonghoadonchu = $row['TongHoaDonChu'];
            $entity->thuegtgt = $row['ThueGTGT'];
            $entity->phuongthucthanhtoan = $row['PhuongThucThanhToan'];
            $entity->laisuat = $row['LaiSuat'];
            $entity->thoihan = $row['ThoiHan'];
            $entity->tiendinhky = $row['TienDinhKy'];
            $entity->ghichu = $row['GhiChu'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_by_thoihan($value) {
        $db = new dbhelper();
        $query = "SELECT * FROM HoaDon WHERE thoihan = #thoihan#";
        $db->setQuery($query);
        $db->set_string_params($value);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new hoadon();
            $entity->id = $row['Id'];
            $entity->ngaythang = $row['NgayThang'];
            $entity->loaihoadon = $row['LoaiHoaDon'];
            $entity->khachhangid = $row['KhachHangID'];
            $entity->tenkhachhang = $row['TenKhachHang'];
            $entity->tendonvi = $row['TenDonVi'];
            $entity->diachi = $row['DiaChi'];
            $entity->sodienthoai = $row['SoDienThoai'];
            $entity->sotaikhoan = $row['SoTaiKhoan'];
            $entity->tenxe = $row['TenXe'];
            $entity->sokhung = $row['SoKhung'];
            $entity->somay = $row['SoMay'];
            $entity->gia = $row['Gia'];
            $entity->tonghoadonso = $row['TongHoaDonSo'];
            $entity->tonghoadonchu = $row['TongHoaDonChu'];
            $entity->thuegtgt = $row['ThueGTGT'];
            $entity->phuongthucthanhtoan = $row['PhuongThucThanhToan'];
            $entity->laisuat = $row['LaiSuat'];
            $entity->thoihan = $row['ThoiHan'];
            $entity->tiendinhky = $row['TienDinhKy'];
            $entity->ghichu = $row['GhiChu'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_by_tiendinhky($value) {
        $db = new dbhelper();
        $query = "SELECT * FROM HoaDon WHERE tiendinhky = #tiendinhky#";
        $db->setQuery($query);
        $db->set_string_params($value);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new hoadon();
            $entity->id = $row['Id'];
            $entity->ngaythang = $row['NgayThang'];
            $entity->loaihoadon = $row['LoaiHoaDon'];
            $entity->khachhangid = $row['KhachHangID'];
            $entity->tenkhachhang = $row['TenKhachHang'];
            $entity->tendonvi = $row['TenDonVi'];
            $entity->diachi = $row['DiaChi'];
            $entity->sodienthoai = $row['SoDienThoai'];
            $entity->sotaikhoan = $row['SoTaiKhoan'];
            $entity->tenxe = $row['TenXe'];
            $entity->sokhung = $row['SoKhung'];
            $entity->somay = $row['SoMay'];
            $entity->gia = $row['Gia'];
            $entity->tonghoadonso = $row['TongHoaDonSo'];
            $entity->tonghoadonchu = $row['TongHoaDonChu'];
            $entity->thuegtgt = $row['ThueGTGT'];
            $entity->phuongthucthanhtoan = $row['PhuongThucThanhToan'];
            $entity->laisuat = $row['LaiSuat'];
            $entity->thoihan = $row['ThoiHan'];
            $entity->tiendinhky = $row['TienDinhKy'];
            $entity->ghichu = $row['GhiChu'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_by_ghichu($value) {
        $db = new dbhelper();
        $query = "SELECT * FROM HoaDon WHERE ghichu = #ghichu#";
        $db->setQuery($query);
        $db->set_string_params($value);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new hoadon();
            $entity->id = $row['Id'];
            $entity->ngaythang = $row['NgayThang'];
            $entity->loaihoadon = $row['LoaiHoaDon'];
            $entity->khachhangid = $row['KhachHangID'];
            $entity->tenkhachhang = $row['TenKhachHang'];
            $entity->tendonvi = $row['TenDonVi'];
            $entity->diachi = $row['DiaChi'];
            $entity->sodienthoai = $row['SoDienThoai'];
            $entity->sotaikhoan = $row['SoTaiKhoan'];
            $entity->tenxe = $row['TenXe'];
            $entity->sokhung = $row['SoKhung'];
            $entity->somay = $row['SoMay'];
            $entity->gia = $row['Gia'];
            $entity->tonghoadonso = $row['TongHoaDonSo'];
            $entity->tonghoadonchu = $row['TongHoaDonChu'];
            $entity->thuegtgt = $row['ThueGTGT'];
            $entity->phuongthucthanhtoan = $row['PhuongThucThanhToan'];
            $entity->laisuat = $row['LaiSuat'];
            $entity->thoihan = $row['ThoiHan'];
            $entity->tiendinhky = $row['TienDinhKy'];
            $entity->ghichu = $row['GhiChu'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_by_isdeleted($value) {
        $db = new dbhelper();
        $query = "SELECT * FROM HoaDon WHERE isdeleted = #isdeleted#";
        $db->setQuery($query);
        $db->set_string_params($value);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new hoadon();
            $entity->id = $row['Id'];
            $entity->ngaythang = $row['NgayThang'];
            $entity->loaihoadon = $row['LoaiHoaDon'];
            $entity->khachhangid = $row['KhachHangID'];
            $entity->tenkhachhang = $row['TenKhachHang'];
            $entity->tendonvi = $row['TenDonVi'];
            $entity->diachi = $row['DiaChi'];
            $entity->sodienthoai = $row['SoDienThoai'];
            $entity->sotaikhoan = $row['SoTaiKhoan'];
            $entity->tenxe = $row['TenXe'];
            $entity->sokhung = $row['SoKhung'];
            $entity->somay = $row['SoMay'];
            $entity->gia = $row['Gia'];
            $entity->tonghoadonso = $row['TongHoaDonSo'];
            $entity->tonghoadonchu = $row['TongHoaDonChu'];
            $entity->thuegtgt = $row['ThueGTGT'];
            $entity->phuongthucthanhtoan = $row['PhuongThucThanhToan'];
            $entity->laisuat = $row['LaiSuat'];
            $entity->thoihan = $row['ThoiHan'];
            $entity->tiendinhky = $row['TienDinhKy'];
            $entity->ghichu = $row['GhiChu'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_post_data() {
        $entity = new hoadon();
        $entity->id = $_POST["id"];
        $entity->ngaythang = $_POST["ngaythang"];
        $entity->loaihoadon = $_POST["loaihoadon"];
        $entity->khachhangid = $_POST["khachhangid"];
        $entity->tenkhachhang = $_POST["tenkhachhang"];
        $entity->tendonvi = $_POST["tendonvi"];
        $entity->diachi = $_POST["diachi"];
        $entity->sodienthoai = $_POST["sodienthoai"];
        $entity->sotaikhoan = $_POST["sotaikhoan"];
        $entity->tenxe = $_POST["tenxe"];
        $entity->sokhung = $_POST["sokhung"];
        $entity->somay = $_POST["somay"];
        $entity->gia = $_POST["gia"];
        $entity->tonghoadonso = $_POST["tonghoadonso"];
        $entity->tonghoadonchu = $_POST["tonghoadonchu"];
        $entity->thuegtgt = $_POST["thuegtgt"];
        $entity->phuongthucthanhtoan = $_POST["phuongthucthanhtoan"];
        $entity->laisuat = $_POST["laisuat"];
        $entity->thoihan = $_POST["thoihan"];
        $entity->tiendinhky = $_POST["tiendinhky"];
        $entity->ghichu = $_POST["ghichu"];
        $entity->isdeleted = $_POST["isdeleted"];
        return $entity;
    }

    public static function search($search_key, $begin = 0, $offset = 20, $pager = false, $count = false) {
        $arr = explode(" ", trim($search_key));
        $search = "";
        for ($i = 0; $i < count($arr); $i++) {
            if ($search == "") {
                $search = $search . " WHERE ";
                $search = $search . "(";
                $search = $search . "id LIKE '%" . $arr[$i] . "%'";
                //$search = $search . " || ngaythang LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || loaihoadon LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || khachhangid LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || tenkhachhang LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || tendonvi LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || diachi LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || sodienthoai LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || sotaikhoan LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || tenxe LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || sokhung LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || somay LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || gia LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || tonghoadonso LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || tonghoadonchu LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || thuegtgt LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || phuongthucthanhtoan LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || laisuat LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || thoihan LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || tiendinhky LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || ghichu LIKE '%" . $arr[$i] . "%'";
                
                $search = $search . ")";
                $search = $search . " AND isdeleted = 'N'";
            } else {
                $search = $search . " AND ";
                $search = $search . "(";
                $search = $search . "id LIKE '%" . $arr[$i] . "%'";
                //$search = $search . " || ngaythang LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || loaihoadon LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || khachhangid LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || tenkhachhang LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || tendonvi LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || diachi LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || sodienthoai LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || sotaikhoan LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || tenxe LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || sokhung LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || somay LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || gia LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || tonghoadonso LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || tonghoadonchu LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || thuegtgt LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || phuongthucthanhtoan LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || laisuat LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || thoihan LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || tiendinhky LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || ghichu LIKE '%" . $arr[$i] . "%'";
                
                $search = $search . ")";
            }
            $db = new dbhelper();
            if ($count) {
                $query = "SELECT COUNT(*) FROM HoaDon " . $search;
            } else {
                $query = "SELECT * FROM HoaDon " . $search;
            }
            if ($pager) {
                $query = $query . " LIMIT " . $begin . ", " . $offset;
            }
            $db->setQuery($query);
            //echo $query;
            $result = $db->excute();
            if ($count) {
                $row = mysql_fetch_array($result);
                return $row[0];
            }
            $entity_arr = array();
            $index = 0;
            while ($row = mysql_fetch_array($result)) {
                $entity = new hoadon();
                $entity->id = $row['Id'];
                $entity->ngaythang = $row['NgayThang'];
                $entity->loaihoadon = $row['LoaiHoaDon'];
                $entity->khachhangid = $row['KhachHangID'];
                $entity->tenkhachhang = $row['TenKhachHang'];
                $entity->tendonvi = $row['TenDonVi'];
                $entity->diachi = $row['DiaChi'];
                $entity->sodienthoai = $row['SoDienThoai'];
                $entity->sotaikhoan = $row['SoTaiKhoan'];
                $entity->tenxe = $row['TenXe'];
                $entity->sokhung = $row['SoKhung'];
                $entity->somay = $row['SoMay'];
                $entity->gia = $row['Gia'];
                $entity->tonghoadonso = $row['TongHoaDonSo'];
                $entity->tonghoadonchu = $row['TongHoaDonChu'];
                $entity->thuegtgt = $row['ThueGTGT'];
                $entity->phuongthucthanhtoan = $row['PhuongThucThanhToan'];
                $entity->laisuat = $row['LaiSuat'];
                $entity->thoihan = $row['ThoiHan'];
                $entity->tiendinhky = $row['TienDinhKy'];
                $entity->ghichu = $row['GhiChu'];
                $entity->isdeleted = $row['IsDeleted'];
                $entity_arr[$index] = $entity;
                $index = $index + 1;
            }
            return $entity_arr;
        }
    }

}

?><?

class hoadonchitiet {

    public $id;
    public $hoadonid;
    public $sanpham;
    public $soluong;
    public $isdeleted;

}

class hoadonchitietdb {

    public static function insert(&$entity) {
        $db = new dbhelper();
        $query = "   INSERT INTO HoaDonChiTiet ( HoaDonID , SanPham , SoLuong ,  IsDeleted) VALUES ( #HoaDonID#, #SanPham#, #SoLuong#, #IsDeleted#)";
        $db->setQuery($query);
        $db->set_string_params("HoaDonID", $entity->hoadonid);
        $db->set_string_params("SanPham", $entity->sanpham);
        $db->set_string_params("SoLuong", $entity->soluong);
        $db->set_string_params("IsDeleted", $entity->isdeleted);
        return $db->excute();
    }

    public static function update(&$entity) {
        $db = new dbhelper();
        $query = "UPDATE HoaDonChiTiet SET HoaDonID = #HoaDonID#, SanPham = #SanPham#, SoLuong = #SoLuong#, IsDeleted = #IsDeleted# WHERE Id = #Id#";
        $db->setQuery($query);
        $db->set_string_params("Id", $entity->id);
        $db->set_string_params("HoaDonID", $entity->hoadonid);
        $db->set_string_params("SanPham", $entity->sanpham);
        $db->set_string_params("SoLuong", $entity->soluong);
        $db->set_string_params("IsDeleted", $entity->isdeleted);
        return $db->excute();
    }

    public static function get_all() {
        $db = new dbhelper();
        $query = "SELECT * FROM HoaDonChiTiet";
        $db->setQuery($query);
        $result = $db->excute();
        $entity_arr = array();
        $index = 0;
        while ($row = mysql_fetch_array($result)) {
            $entity = new hoadonchitiet();
            $entity->id = $row['Id'];
            $entity->hoadonid = $row['HoaDonID'];
            $entity->sanpham = $row['SanPham'];
            $entity->soluong = $row['SoLuong'];
            $entity->isdeleted = $row['IsDeleted'];
            $entity_arr[$index] = $entity;
            $index = $index + 1;
        }
        return $entity_arr;
    }

    public static function get(&$entity) {
        $db = new dbhelper();
        $query = "SELECT * FROM HoaDonChiTiet WHERE Id = #Id#";
        $db->setQuery($query);
        $db->set_string_params("Id", $entity->id);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new hoadonchitiet();
            $entity->id = $row['Id'];
            $entity->hoadonid = $row['HoaDonID'];
            $entity->sanpham = $row['SanPham'];
            $entity->soluong = $row['SoLuong'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_by_id($value) {
        $db = new dbhelper();
        $query = "SELECT * FROM HoaDonChiTiet WHERE id = #id#";
        $db->setQuery($query);
        $db->set_string_params($value);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new hoadonchitiet();
            $entity->id = $row['Id'];
            $entity->hoadonid = $row['HoaDonID'];
            $entity->sanpham = $row['SanPham'];
            $entity->soluong = $row['SoLuong'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_by_hoadonid($value) {
        $db = new dbhelper();
        $query = "SELECT * FROM HoaDonChiTiet WHERE hoadonid = #hoadonid#";
        $db->setQuery($query);
        $db->set_string_params($value);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new hoadonchitiet();
            $entity->id = $row['Id'];
            $entity->hoadonid = $row['HoaDonID'];
            $entity->sanpham = $row['SanPham'];
            $entity->soluong = $row['SoLuong'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_by_sanpham($value) {
        $db = new dbhelper();
        $query = "SELECT * FROM HoaDonChiTiet WHERE sanpham = #sanpham#";
        $db->setQuery($query);
        $db->set_string_params($value);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new hoadonchitiet();
            $entity->id = $row['Id'];
            $entity->hoadonid = $row['HoaDonID'];
            $entity->sanpham = $row['SanPham'];
            $entity->soluong = $row['SoLuong'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_by_soluong($value) {
        $db = new dbhelper();
        $query = "SELECT * FROM HoaDonChiTiet WHERE soluong = #soluong#";
        $db->setQuery($query);
        $db->set_string_params($value);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new hoadonchitiet();
            $entity->id = $row['Id'];
            $entity->hoadonid = $row['HoaDonID'];
            $entity->sanpham = $row['SanPham'];
            $entity->soluong = $row['SoLuong'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_by_isdeleted($value) {
        $db = new dbhelper();
        $query = "SELECT * FROM HoaDonChiTiet WHERE isdeleted = #isdeleted#";
        $db->setQuery($query);
        $db->set_string_params($value);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new hoadonchitiet();
            $entity->id = $row['Id'];
            $entity->hoadonid = $row['HoaDonID'];
            $entity->sanpham = $row['SanPham'];
            $entity->soluong = $row['SoLuong'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_post_data() {
        $entity = new hoadonchitiet();
        $entity->id = $_POST["id"];
        $entity->hoadonid = $_POST["hoadonid"];
        $entity->sanpham = $_POST["sanpham"];
        $entity->soluong = $_POST["soluong"];
        $entity->isdeleted = $_POST["isdeleted"];
        return $entity;
    }

    public static function search($search_key) {
        $arr = explode(" ", trim($search_key));
        $search = "";
        for ($i = 0; $i < count($arr); $i++) {
            if ($search == "") {
                $search = $search . " WHERE ";
                $search = $search . "(";
                $search = $search . "id LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || hoadonid LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || sanpham LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || soluong LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || isdeleted LIKE '%" . $arr[$i] . "%'";
                $search = $search . ")";
            } else {
                $search = $search . " AND ";
                $search = $search . "(";
                $search = $search . "id LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || hoadonid LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || sanpham LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || soluong LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || isdeleted LIKE '%" . $arr[$i] . "%'";
                $search = $search . ")";
            }
            $db = new dbhelper();
            $query = "SELECT * FROM HoaDonChiTiet" . $search;
            $db->setQuery($query);
            $result = $db->excute();
            $entity_arr = array();
            $index = 0;
            while ($row = mysql_fetch_array($result)) {
                $entity = new hoadonchitiet();
                $entity->id = $row['Id'];
                $entity->hoadonid = $row['HoaDonID'];
                $entity->sanpham = $row['SanPham'];
                $entity->soluong = $row['SoLuong'];
                $entity->isdeleted = $row['IsDeleted'];
                $entity_arr[$index] = $entity;
                $index = $index + 1;
            }
            return $entity_arr;
        }
    }

}

?><?

class hoadonthanhtoan {

    public $id;
    public $hoadon;
    public $ngaythang;
    public $khachhang;
    public $sotien;
    public $sotienchu;
    public $ghichu;
    public $isdeleted;

}

class hoadonthanhtoandb {

    public static function insert(&$entity) {
        $db = new dbhelper();
        $query = "      INSERT INTO HoaDonThanhToan ( HoaDon , NgayThang , KhachHang , SoTien , SoTienChu , GhiChu ,  IsDeleted) VALUES ( #HoaDon#, #NgayThang#, #KhachHang#, #SoTien#, #SoTienChu#, #GhiChu#, #IsDeleted#)";
        $db->setQuery($query);
        $db->set_string_params("HoaDon", $entity->hoadon);
        $db->set_string_params("NgayThang", date('Y-m-d H:i:s', strtotime($entity->ngaythang)));
        $db->set_string_params("KhachHang", $entity->khachhang);
        $db->set_string_params("SoTien", $entity->sotien);
        $db->set_string_params("SoTienChu", $entity->sotienchu);
        $db->set_string_params("GhiChu", $entity->ghichu);
        $db->set_string_params("IsDeleted", $entity->isdeleted);
        return $db->excute();
    }

    public static function update(&$entity) {
        $db = new dbhelper();
        $query = "UPDATE HoaDonThanhToan SET HoaDon = #HoaDon#, NgayThang = #NgayThang#, KhachHang = #KhachHang#, SoTien = #SoTien#, SoTienChu = #SoTienChu#, GhiChu = #GhiChu#, IsDeleted = #IsDeleted# WHERE Id = #Id#";
        $db->setQuery($query);
        $db->set_string_params("Id", $entity->id);
        $db->set_string_params("HoaDon", $entity->hoadon);
        $db->set_string_params("NgayThang", $entity->ngaythang);
        $db->set_string_params("KhachHang", $entity->khachhang);
        $db->set_string_params("SoTien", $entity->sotien);
        $db->set_string_params("SoTienChu", $entity->sotienchu);
        $db->set_string_params("GhiChu", $entity->ghichu);
        $db->set_string_params("IsDeleted", $entity->isdeleted);
        return $db->excute();
    }

    public static function get_all() {
        $db = new dbhelper();
        $query = "SELECT * FROM HoaDonThanhToan";
        $db->setQuery($query);
        $result = $db->excute();
        $entity_arr = array();
        $index = 0;
        while ($row = mysql_fetch_array($result)) {
            $entity = new hoadonthanhtoan();
            $entity->id = $row['Id'];
            $entity->hoadon = $row['HoaDon'];
            $entity->ngaythang = $row['NgayThang'];
            $entity->khachhang = $row['KhachHang'];
            $entity->sotien = $row['SoTien'];
            $entity->sotienchu = $row['SoTienChu'];
            $entity->ghichu = $row['GhiChu'];
            $entity->isdeleted = $row['IsDeleted'];
            $entity_arr[$index] = $entity;
            $index = $index + 1;
        }
        return $entity_arr;
    }

    public static function find_by_hoadon_id($hoadon_id) {
        $db = new dbhelper();
        $query = "SELECT * FROM HoaDonThanhToan WHERE HoaDon  = #id# ";
        $db->setQuery($query);
        $db->set_int_params("id", $hoadon_id);
        $result = $db->excute();
        $entity_arr = array();
        $index = 0;
        while ($row = mysql_fetch_array($result)) {
            $entity = new hoadonthanhtoan();
            $entity->id = $row['Id'];
            $entity->hoadon = $row['HoaDon'];
            $entity->ngaythang = $row['NgayThang'];
            $entity->khachhang = $row['KhachHang'];
            $entity->sotien = $row['SoTien'];
            $entity->sotienchu = $row['SoTienChu'];
            $entity->ghichu = $row['GhiChu'];
            $entity->isdeleted = $row['IsDeleted'];
            $entity_arr[$index] = $entity;
            $index = $index + 1;
        }
        return $entity_arr;
    }

    public static function get(&$entity) {
        $db = new dbhelper();
        $query = "SELECT * FROM HoaDonThanhToan WHERE Id = #Id#";
        $db->setQuery($query);
        $db->set_string_params("Id", $entity->id);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new hoadonthanhtoan();
            $entity->id = $row['Id'];
            $entity->hoadon = $row['HoaDon'];
            $entity->ngaythang = $row['NgayThang'];
            $entity->khachhang = $row['KhachHang'];
            $entity->sotien = $row['SoTien'];
            $entity->sotienchu = $row['SoTienChu'];
            $entity->ghichu = $row['GhiChu'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_by_id($value) {
        $db = new dbhelper();
        $query = "SELECT * FROM HoaDonThanhToan WHERE id = #id#";
        $db->setQuery($query);
        $db->set_string_params($value);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new hoadonthanhtoan();
            $entity->id = $row['Id'];
            $entity->hoadon = $row['HoaDon'];
            $entity->ngaythang = $row['NgayThang'];
            $entity->khachhang = $row['KhachHang'];
            $entity->sotien = $row['SoTien'];
            $entity->sotienchu = $row['SoTienChu'];
            $entity->ghichu = $row['GhiChu'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_by_hoadon($value) {
        $db = new dbhelper();
        $query = "SELECT * FROM HoaDonThanhToan WHERE hoadon = #hoadon#";
        $db->setQuery($query);
        $db->set_string_params($value);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new hoadonthanhtoan();
            $entity->id = $row['Id'];
            $entity->hoadon = $row['HoaDon'];
            $entity->ngaythang = $row['NgayThang'];
            $entity->khachhang = $row['KhachHang'];
            $entity->sotien = $row['SoTien'];
            $entity->sotienchu = $row['SoTienChu'];
            $entity->ghichu = $row['GhiChu'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_by_ngaythang($value) {
        $db = new dbhelper();
        $query = "SELECT * FROM HoaDonThanhToan WHERE ngaythang = #ngaythang#";
        $db->setQuery($query);
        $db->set_string_params($value);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new hoadonthanhtoan();
            $entity->id = $row['Id'];
            $entity->hoadon = $row['HoaDon'];
            $entity->ngaythang = $row['NgayThang'];
            $entity->khachhang = $row['KhachHang'];
            $entity->sotien = $row['SoTien'];
            $entity->sotienchu = $row['SoTienChu'];
            $entity->ghichu = $row['GhiChu'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_by_khachhang($value) {
        $db = new dbhelper();
        $query = "SELECT * FROM HoaDonThanhToan WHERE khachhang = #khachhang#";
        $db->setQuery($query);
        $db->set_string_params($value);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new hoadonthanhtoan();
            $entity->id = $row['Id'];
            $entity->hoadon = $row['HoaDon'];
            $entity->ngaythang = $row['NgayThang'];
            $entity->khachhang = $row['KhachHang'];
            $entity->sotien = $row['SoTien'];
            $entity->sotienchu = $row['SoTienChu'];
            $entity->ghichu = $row['GhiChu'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_by_sotien($value) {
        $db = new dbhelper();
        $query = "SELECT * FROM HoaDonThanhToan WHERE sotien = #sotien#";
        $db->setQuery($query);
        $db->set_string_params($value);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new hoadonthanhtoan();
            $entity->id = $row['Id'];
            $entity->hoadon = $row['HoaDon'];
            $entity->ngaythang = $row['NgayThang'];
            $entity->khachhang = $row['KhachHang'];
            $entity->sotien = $row['SoTien'];
            $entity->sotienchu = $row['SoTienChu'];
            $entity->ghichu = $row['GhiChu'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_by_sotienchu($value) {
        $db = new dbhelper();
        $query = "SELECT * FROM HoaDonThanhToan WHERE sotienchu = #sotienchu#";
        $db->setQuery($query);
        $db->set_string_params($value);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new hoadonthanhtoan();
            $entity->id = $row['Id'];
            $entity->hoadon = $row['HoaDon'];
            $entity->ngaythang = $row['NgayThang'];
            $entity->khachhang = $row['KhachHang'];
            $entity->sotien = $row['SoTien'];
            $entity->sotienchu = $row['SoTienChu'];
            $entity->ghichu = $row['GhiChu'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_by_ghichu($value) {
        $db = new dbhelper();
        $query = "SELECT * FROM HoaDonThanhToan WHERE ghichu = #ghichu#";
        $db->setQuery($query);
        $db->set_string_params($value);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new hoadonthanhtoan();
            $entity->id = $row['Id'];
            $entity->hoadon = $row['HoaDon'];
            $entity->ngaythang = $row['NgayThang'];
            $entity->khachhang = $row['KhachHang'];
            $entity->sotien = $row['SoTien'];
            $entity->sotienchu = $row['SoTienChu'];
            $entity->ghichu = $row['GhiChu'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_by_isdeleted($value) {
        $db = new dbhelper();
        $query = "SELECT * FROM HoaDonThanhToan WHERE isdeleted = #isdeleted#";
        $db->setQuery($query);
        $db->set_string_params($value);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new hoadonthanhtoan();
            $entity->id = $row['Id'];
            $entity->hoadon = $row['HoaDon'];
            $entity->ngaythang = $row['NgayThang'];
            $entity->khachhang = $row['KhachHang'];
            $entity->sotien = $row['SoTien'];
            $entity->sotienchu = $row['SoTienChu'];
            $entity->ghichu = $row['GhiChu'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_post_data() {
        $entity = new hoadonthanhtoan();
        $entity->id = $_POST["id"];
        $entity->hoadon = $_POST["hoadon"];
        $entity->ngaythang = $_POST["ngaythang"];
        $entity->khachhang = $_POST["khachhang"];
        $entity->sotien = $_POST["sotien"];
        $entity->sotienchu = $_POST["sotienchu"];
        $entity->ghichu = $_POST["ghichu"];
        $entity->isdeleted = $_POST["isdeleted"];
        return $entity;
    }

    public static function search($search_key) {
        $arr = explode(" ", trim($search_key));
        $search = "";
        for ($i = 0; $i < count($arr); $i++) {
            if ($search == "") {
                $search = $search . " WHERE ";
                $search = $search . "(";
                $search = $search . "id LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || hoadon LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || ngaythang LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || khachhang LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || sotien LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || sotienchu LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || ghichu LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || isdeleted LIKE '%" . $arr[$i] . "%'";
                $search = $search . ")";
            } else {
                $search = $search . " AND ";
                $search = $search . "(";
                $search = $search . "id LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || hoadon LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || ngaythang LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || khachhang LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || sotien LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || sotienchu LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || ghichu LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || isdeleted LIKE '%" . $arr[$i] . "%'";
                $search = $search . ")";
            }
            $db = new dbhelper();
            $query = "SELECT * FROM HoaDonThanhToan" . $search;
            $db->setQuery($query);
            $result = $db->excute();
            $entity_arr = array();
            $index = 0;
            while ($row = mysql_fetch_array($result)) {
                $entity = new hoadonthanhtoan();
                $entity->id = $row['Id'];
                $entity->hoadon = $row['HoaDon'];
                $entity->ngaythang = $row['NgayThang'];
                $entity->khachhang = $row['KhachHang'];
                $entity->sotien = $row['SoTien'];
                $entity->sotienchu = $row['SoTienChu'];
                $entity->ghichu = $row['GhiChu'];
                $entity->isdeleted = $row['IsDeleted'];
                $entity_arr[$index] = $entity;
                $index = $index + 1;
            }
            return $entity_arr;
        }
    }

}

?><?

class khachhang {

    public $id;
    public $hoten;
    public $namsinh;
    public $diachi;
    public $sodienthoai;
    public $quanhuyen;
    public $socmnd;
    public $ngaycapcmnd;
    public $noicapcmnd;
    public $ghichu;
    public $isdeleted;

}

class khachhangdb {

    public static function insert(&$entity) {
        $db = new dbhelper();
        $query = "         INSERT INTO KhachHang ( HoTen , NamSinh , DiaChi , SoDienThoai , QuanHuyen , SoCMND , NgayCapCMND , NoiCapCMND , GhiChu ,  IsDeleted) VALUES ( #HoTen#, #NamSinh#, #DiaChi#, #SoDienThoai#, #QuanHuyen#, #SoCMND#, #NgayCapCMND#, #NoiCapCMND#, #GhiChu#, #IsDeleted#)";
        $db->setQuery($query);
        $db->set_string_params("HoTen", $entity->hoten);
        $db->set_string_params("NamSinh", $entity->namsinh);
        $db->set_string_params("DiaChi", $entity->diachi);
        $db->set_string_params("SoDienThoai", $entity->sodienthoai);
        $db->set_string_params("QuanHuyen", $entity->quanhuyen);
        $db->set_string_params("SoCMND", $entity->socmnd);
        $db->set_string_params("NgayCapCMND", $entity->ngaycapcmnd);
        $db->set_string_params("NoiCapCMND", $entity->noicapcmnd);
        $db->set_string_params("GhiChu", $entity->ghichu);
        $db->set_string_params("IsDeleted", $entity->isdeleted);
        return $db->excute();
    }

    public static function update(&$entity) {
        $db = new dbhelper();
        $query = "UPDATE KhachHang SET HoTen = #HoTen#, NamSinh = #NamSinh#, DiaChi = #DiaChi#, SoDienThoai = #SoDienThoai#, QuanHuyen = #QuanHuyen#, SoCMND = #SoCMND#, NgayCapCMND = #NgayCapCMND#, NoiCapCMND = #NoiCapCMND#, GhiChu = #GhiChu#, IsDeleted = #IsDeleted# WHERE Id = #Id#";
        $db->setQuery($query);
        $db->set_string_params("Id", $entity->id);
        $db->set_string_params("HoTen", $entity->hoten);
        $db->set_string_params("NamSinh", $entity->namsinh);
        $db->set_string_params("DiaChi", $entity->diachi);
        $db->set_string_params("SoDienThoai", $entity->sodienthoai);
        $db->set_string_params("QuanHuyen", $entity->quanhuyen);
        $db->set_string_params("SoCMND", $entity->socmnd);
        $db->set_string_params("NgayCapCMND", $entity->ngaycapcmnd);
        $db->set_string_params("NoiCapCMND", $entity->noicapcmnd);
        $db->set_string_params("GhiChu", $entity->ghichu);
        $db->set_string_params("IsDeleted", $entity->isdeleted);
        return $db->excute();
    }

    public static function get_all() {
        $db = new dbhelper();
        $query = "SELECT * FROM KhachHang";
        $db->setQuery($query);
        $result = $db->excute();
        $entity_arr = array();
        $index = 0;
        while ($row = mysql_fetch_array($result)) {
            $entity = new khachhang();
            $entity->id = $row['Id'];
            $entity->hoten = $row['HoTen'];
            $entity->namsinh = $row['NamSinh'];
            $entity->diachi = $row['DiaChi'];
            $entity->sodienthoai = $row['SoDienThoai'];
            $entity->quanhuyen = $row['QuanHuyen'];
            $entity->socmnd = $row['SoCMND'];
            $entity->ngaycapcmnd = $row['NgayCapCMND'];
            $entity->noicapcmnd = $row['NoiCapCMND'];
            $entity->ghichu = $row['GhiChu'];
            $entity->isdeleted = $row['IsDeleted'];
            $entity_arr[$index] = $entity;
            $index = $index + 1;
        }
        return $entity_arr;
    }

    public static function get(&$entity) {
        $db = new dbhelper();
        $query = "SELECT * FROM KhachHang WHERE Id = #Id#";
        $db->setQuery($query);
        $db->set_string_params("Id", $entity->id);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new khachhang();
            $entity->id = $row['Id'];
            $entity->hoten = $row['HoTen'];
            $entity->namsinh = $row['NamSinh'];
            $entity->diachi = $row['DiaChi'];
            $entity->sodienthoai = $row['SoDienThoai'];
            $entity->quanhuyen = $row['QuanHuyen'];
            $entity->socmnd = $row['SoCMND'];
            $entity->ngaycapcmnd = $row['NgayCapCMND'];
            $entity->noicapcmnd = $row['NoiCapCMND'];
            $entity->ghichu = $row['GhiChu'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_by_id($value) {
        $db = new dbhelper();
        $query = "SELECT * FROM KhachHang WHERE id = #id#";
        $db->setQuery($query);
        $db->set_string_params($value);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new khachhang();
            $entity->id = $row['Id'];
            $entity->hoten = $row['HoTen'];
            $entity->namsinh = $row['NamSinh'];
            $entity->diachi = $row['DiaChi'];
            $entity->sodienthoai = $row['SoDienThoai'];
            $entity->quanhuyen = $row['QuanHuyen'];
            $entity->socmnd = $row['SoCMND'];
            $entity->ngaycapcmnd = $row['NgayCapCMND'];
            $entity->noicapcmnd = $row['NoiCapCMND'];
            $entity->ghichu = $row['GhiChu'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_by_hoten($value) {
        $db = new dbhelper();
        $query = "SELECT * FROM KhachHang WHERE hoten = #hoten#";
        $db->setQuery($query);
        $db->set_string_params($value);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new khachhang();
            $entity->id = $row['Id'];
            $entity->hoten = $row['HoTen'];
            $entity->namsinh = $row['NamSinh'];
            $entity->diachi = $row['DiaChi'];
            $entity->sodienthoai = $row['SoDienThoai'];
            $entity->quanhuyen = $row['QuanHuyen'];
            $entity->socmnd = $row['SoCMND'];
            $entity->ngaycapcmnd = $row['NgayCapCMND'];
            $entity->noicapcmnd = $row['NoiCapCMND'];
            $entity->ghichu = $row['GhiChu'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_by_namsinh($value) {
        $db = new dbhelper();
        $query = "SELECT * FROM KhachHang WHERE namsinh = #namsinh#";
        $db->setQuery($query);
        $db->set_string_params($value);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new khachhang();
            $entity->id = $row['Id'];
            $entity->hoten = $row['HoTen'];
            $entity->namsinh = $row['NamSinh'];
            $entity->diachi = $row['DiaChi'];
            $entity->sodienthoai = $row['SoDienThoai'];
            $entity->quanhuyen = $row['QuanHuyen'];
            $entity->socmnd = $row['SoCMND'];
            $entity->ngaycapcmnd = $row['NgayCapCMND'];
            $entity->noicapcmnd = $row['NoiCapCMND'];
            $entity->ghichu = $row['GhiChu'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_by_diachi($value) {
        $db = new dbhelper();
        $query = "SELECT * FROM KhachHang WHERE diachi = #diachi#";
        $db->setQuery($query);
        $db->set_string_params($value);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new khachhang();
            $entity->id = $row['Id'];
            $entity->hoten = $row['HoTen'];
            $entity->namsinh = $row['NamSinh'];
            $entity->diachi = $row['DiaChi'];
            $entity->sodienthoai = $row['SoDienThoai'];
            $entity->quanhuyen = $row['QuanHuyen'];
            $entity->socmnd = $row['SoCMND'];
            $entity->ngaycapcmnd = $row['NgayCapCMND'];
            $entity->noicapcmnd = $row['NoiCapCMND'];
            $entity->ghichu = $row['GhiChu'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_by_sodienthoai($value) {
        $db = new dbhelper();
        $query = "SELECT * FROM KhachHang WHERE sodienthoai = #sodienthoai#";
        $db->setQuery($query);
        $db->set_string_params($value);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new khachhang();
            $entity->id = $row['Id'];
            $entity->hoten = $row['HoTen'];
            $entity->namsinh = $row['NamSinh'];
            $entity->diachi = $row['DiaChi'];
            $entity->sodienthoai = $row['SoDienThoai'];
            $entity->quanhuyen = $row['QuanHuyen'];
            $entity->socmnd = $row['SoCMND'];
            $entity->ngaycapcmnd = $row['NgayCapCMND'];
            $entity->noicapcmnd = $row['NoiCapCMND'];
            $entity->ghichu = $row['GhiChu'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_by_quanhuyen($value) {
        $db = new dbhelper();
        $query = "SELECT * FROM KhachHang WHERE quanhuyen = #quanhuyen#";
        $db->setQuery($query);
        $db->set_string_params($value);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new khachhang();
            $entity->id = $row['Id'];
            $entity->hoten = $row['HoTen'];
            $entity->namsinh = $row['NamSinh'];
            $entity->diachi = $row['DiaChi'];
            $entity->sodienthoai = $row['SoDienThoai'];
            $entity->quanhuyen = $row['QuanHuyen'];
            $entity->socmnd = $row['SoCMND'];
            $entity->ngaycapcmnd = $row['NgayCapCMND'];
            $entity->noicapcmnd = $row['NoiCapCMND'];
            $entity->ghichu = $row['GhiChu'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_by_socmnd($value) {
        $db = new dbhelper();
        $query = "SELECT * FROM KhachHang WHERE socmnd = #socmnd#";
        $db->setQuery($query);
        $db->set_string_params($value);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new khachhang();
            $entity->id = $row['Id'];
            $entity->hoten = $row['HoTen'];
            $entity->namsinh = $row['NamSinh'];
            $entity->diachi = $row['DiaChi'];
            $entity->sodienthoai = $row['SoDienThoai'];
            $entity->quanhuyen = $row['QuanHuyen'];
            $entity->socmnd = $row['SoCMND'];
            $entity->ngaycapcmnd = $row['NgayCapCMND'];
            $entity->noicapcmnd = $row['NoiCapCMND'];
            $entity->ghichu = $row['GhiChu'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_by_ngaycapcmnd($value) {
        $db = new dbhelper();
        $query = "SELECT * FROM KhachHang WHERE ngaycapcmnd = #ngaycapcmnd#";
        $db->setQuery($query);
        $db->set_string_params($value);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new khachhang();
            $entity->id = $row['Id'];
            $entity->hoten = $row['HoTen'];
            $entity->namsinh = $row['NamSinh'];
            $entity->diachi = $row['DiaChi'];
            $entity->sodienthoai = $row['SoDienThoai'];
            $entity->quanhuyen = $row['QuanHuyen'];
            $entity->socmnd = $row['SoCMND'];
            $entity->ngaycapcmnd = $row['NgayCapCMND'];
            $entity->noicapcmnd = $row['NoiCapCMND'];
            $entity->ghichu = $row['GhiChu'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_by_noicapcmnd($value) {
        $db = new dbhelper();
        $query = "SELECT * FROM KhachHang WHERE noicapcmnd = #noicapcmnd#";
        $db->setQuery($query);
        $db->set_string_params($value);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new khachhang();
            $entity->id = $row['Id'];
            $entity->hoten = $row['HoTen'];
            $entity->namsinh = $row['NamSinh'];
            $entity->diachi = $row['DiaChi'];
            $entity->sodienthoai = $row['SoDienThoai'];
            $entity->quanhuyen = $row['QuanHuyen'];
            $entity->socmnd = $row['SoCMND'];
            $entity->ngaycapcmnd = $row['NgayCapCMND'];
            $entity->noicapcmnd = $row['NoiCapCMND'];
            $entity->ghichu = $row['GhiChu'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_by_ghichu($value) {
        $db = new dbhelper();
        $query = "SELECT * FROM KhachHang WHERE ghichu = #ghichu#";
        $db->setQuery($query);
        $db->set_string_params($value);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new khachhang();
            $entity->id = $row['Id'];
            $entity->hoten = $row['HoTen'];
            $entity->namsinh = $row['NamSinh'];
            $entity->diachi = $row['DiaChi'];
            $entity->sodienthoai = $row['SoDienThoai'];
            $entity->quanhuyen = $row['QuanHuyen'];
            $entity->socmnd = $row['SoCMND'];
            $entity->ngaycapcmnd = $row['NgayCapCMND'];
            $entity->noicapcmnd = $row['NoiCapCMND'];
            $entity->ghichu = $row['GhiChu'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_by_isdeleted($value) {
        $db = new dbhelper();
        $query = "SELECT * FROM KhachHang WHERE isdeleted = #isdeleted#";
        $db->setQuery($query);
        $db->set_string_params($value);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new khachhang();
            $entity->id = $row['Id'];
            $entity->hoten = $row['HoTen'];
            $entity->namsinh = $row['NamSinh'];
            $entity->diachi = $row['DiaChi'];
            $entity->sodienthoai = $row['SoDienThoai'];
            $entity->quanhuyen = $row['QuanHuyen'];
            $entity->socmnd = $row['SoCMND'];
            $entity->ngaycapcmnd = $row['NgayCapCMND'];
            $entity->noicapcmnd = $row['NoiCapCMND'];
            $entity->ghichu = $row['GhiChu'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_post_data() {
        $entity = new khachhang();
        $entity->id = $_POST["id"];
        $entity->hoten = $_POST["hoten"];
        $entity->namsinh = $_POST["namsinh"];
        $entity->diachi = $_POST["diachi"];
        $entity->sodienthoai = $_POST["sodienthoai"];
        $entity->quanhuyen = $_POST["quanhuyen"];
        $entity->socmnd = $_POST["socmnd"];
        $entity->ngaycapcmnd = $_POST["ngaycapcmnd"];
        $entity->noicapcmnd = $_POST["noicapcmnd"];
        $entity->ghichu = $_POST["ghichu"];
        $entity->isdeleted = $_POST["isdeleted"];
        return $entity;
    }

    public static function search($search_key) {
        $arr = explode(" ", trim($search_key));
        $search = "";
        for ($i = 0; $i < count($arr); $i++) {
            if ($search == "") {
                $search = $search . " WHERE ";
                $search = $search . "(";
                $search = $search . "id LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || hoten LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || namsinh LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || diachi LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || sodienthoai LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || quanhuyen LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || socmnd LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || ngaycapcmnd LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || noicapcmnd LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || ghichu LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || isdeleted LIKE '%" . $arr[$i] . "%'";
                $search = $search . ")";
            } else {
                $search = $search . " AND ";
                $search = $search . "(";
                $search = $search . "id LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || hoten LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || namsinh LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || diachi LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || sodienthoai LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || quanhuyen LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || socmnd LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || ngaycapcmnd LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || noicapcmnd LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || ghichu LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || isdeleted LIKE '%" . $arr[$i] . "%'";
                $search = $search . ")";
            }
            $db = new dbhelper();
            $query = "SELECT * FROM KhachHang" . $search;
            $db->setQuery($query);
            $result = $db->excute();
            $entity_arr = array();
            $index = 0;
            while ($row = mysql_fetch_array($result)) {
                $entity = new khachhang();
                $entity->id = $row['Id'];
                $entity->hoten = $row['HoTen'];
                $entity->namsinh = $row['NamSinh'];
                $entity->diachi = $row['DiaChi'];
                $entity->sodienthoai = $row['SoDienThoai'];
                $entity->quanhuyen = $row['QuanHuyen'];
                $entity->socmnd = $row['SoCMND'];
                $entity->ngaycapcmnd = $row['NgayCapCMND'];
                $entity->noicapcmnd = $row['NoiCapCMND'];
                $entity->ghichu = $row['GhiChu'];
                $entity->isdeleted = $row['IsDeleted'];
                $entity_arr[$index] = $entity;
                $index = $index + 1;
            }
            return $entity_arr;
        }
    }

}

?><?

class loaisanpham {

    public $id;
    public $ten;
    public $nhasanxuat;
    public $nhacungcap;
    public $mausac;
    public $khohang;
    public $giaso;
    public $giachu;
    public $ghichu;
    public $isdeleted;

}

class loaisanphamdb {

    public static function insert(&$entity) {
        $db = new dbhelper();
        $query = "        INSERT INTO LoaiSanPham ( Ten , NhaSanXuat , NhaCungCap , MauSac , KhoHang , GiaSo , GiaChu , GhiChu ,  IsDeleted) VALUES ( #Ten#, #NhaSanXuat#, #NhaCungCap#, #MauSac#, #KhoHang#, #GiaSo#, #GiaChu#, #GhiChu#, #IsDeleted#)";
        $db->setQuery($query);
        $db->set_string_params("Ten", $entity->ten);
        $db->set_string_params("NhaSanXuat", $entity->nhasanxuat);
        $db->set_string_params("NhaCungCap", $entity->nhacungcap);
        $db->set_string_params("MauSac", $entity->mausac);
        $db->set_string_params("KhoHang", $entity->khohang);
        $db->set_string_params("GiaSo", $entity->giaso);
        $db->set_string_params("GiaChu", $entity->giachu);
        $db->set_string_params("GhiChu", $entity->ghichu);
        $db->set_string_params("IsDeleted", $entity->isdeleted);
        return $db->excute();
    }

    public static function update(&$entity) {
        $db = new dbhelper();
        $query = "UPDATE LoaiSanPham SET Ten = #Ten#, NhaSanXuat = #NhaSanXuat#, NhaCungCap = #NhaCungCap#, MauSac = #MauSac#, KhoHang = #KhoHang#, GiaSo = #GiaSo#, GiaChu = #GiaChu#, GhiChu = #GhiChu#, IsDeleted = #IsDeleted# WHERE Id = #Id#";
        $db->setQuery($query);
        $db->set_string_params("Id", $entity->id);
        $db->set_string_params("Ten", $entity->ten);
        $db->set_string_params("NhaSanXuat", $entity->nhasanxuat);
        $db->set_string_params("NhaCungCap", $entity->nhacungcap);
        $db->set_string_params("MauSac", $entity->mausac);
        $db->set_string_params("KhoHang", $entity->khohang);
        $db->set_string_params("GiaSo", $entity->giaso);
        $db->set_string_params("GiaChu", $entity->giachu);
        $db->set_string_params("GhiChu", $entity->ghichu);
        $db->set_string_params("IsDeleted", $entity->isdeleted);
        return $db->excute();
    }

    public static function get_all() {
        $db = new dbhelper();
        $query = "SELECT * FROM LoaiSanPham";
        $db->setQuery($query);
        $result = $db->excute();
        $entity_arr = array();
        $index = 0;
        while ($row = mysql_fetch_array($result)) {
            $entity = new loaisanpham();
            $entity->id = $row['Id'];
            $entity->ten = $row['Ten'];
            $entity->nhasanxuat = $row['NhaSanXuat'];
            $entity->nhacungcap = $row['NhaCungCap'];
            $entity->mausac = $row['MauSac'];
            $entity->khohang = $row['KhoHang'];
            $entity->giaso = $row['GiaSo'];
            $entity->giachu = $row['GiaChu'];
            $entity->ghichu = $row['GhiChu'];
            $entity->isdeleted = $row['IsDeleted'];
            $entity_arr[$index] = $entity;
            $index = $index + 1;
        }
        return $entity_arr;
    }

    public static function get(&$entity) {
        $db = new dbhelper();
        $query = "SELECT * FROM LoaiSanPham WHERE Id = #Id#";
        $db->setQuery($query);
        $db->set_string_params("Id", $entity->id);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new loaisanpham();
            $entity->id = $row['Id'];
            $entity->ten = $row['Ten'];
            $entity->nhasanxuat = $row['NhaSanXuat'];
            $entity->nhacungcap = $row['NhaCungCap'];
            $entity->mausac = $row['MauSac'];
            $entity->khohang = $row['KhoHang'];
            $entity->giaso = $row['GiaSo'];
            $entity->giachu = $row['GiaChu'];
            $entity->ghichu = $row['GhiChu'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_by_id($value) {
        $db = new dbhelper();
        $query = "SELECT * FROM LoaiSanPham WHERE id = #id#";
        $db->setQuery($query);
        $db->set_string_params($value);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new loaisanpham();
            $entity->id = $row['Id'];
            $entity->ten = $row['Ten'];
            $entity->nhasanxuat = $row['NhaSanXuat'];
            $entity->nhacungcap = $row['NhaCungCap'];
            $entity->mausac = $row['MauSac'];
            $entity->khohang = $row['KhoHang'];
            $entity->giaso = $row['GiaSo'];
            $entity->giachu = $row['GiaChu'];
            $entity->ghichu = $row['GhiChu'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_by_ten($value) {
        $db = new dbhelper();
        $query = "SELECT * FROM LoaiSanPham WHERE ten = #ten#";
        $db->setQuery($query);
        $db->set_string_params($value);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new loaisanpham();
            $entity->id = $row['Id'];
            $entity->ten = $row['Ten'];
            $entity->nhasanxuat = $row['NhaSanXuat'];
            $entity->nhacungcap = $row['NhaCungCap'];
            $entity->mausac = $row['MauSac'];
            $entity->khohang = $row['KhoHang'];
            $entity->giaso = $row['GiaSo'];
            $entity->giachu = $row['GiaChu'];
            $entity->ghichu = $row['GhiChu'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_by_nhasanxuat($value) {
        $db = new dbhelper();
        $query = "SELECT * FROM LoaiSanPham WHERE nhasanxuat = #nhasanxuat#";
        $db->setQuery($query);
        $db->set_string_params($value);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new loaisanpham();
            $entity->id = $row['Id'];
            $entity->ten = $row['Ten'];
            $entity->nhasanxuat = $row['NhaSanXuat'];
            $entity->nhacungcap = $row['NhaCungCap'];
            $entity->mausac = $row['MauSac'];
            $entity->khohang = $row['KhoHang'];
            $entity->giaso = $row['GiaSo'];
            $entity->giachu = $row['GiaChu'];
            $entity->ghichu = $row['GhiChu'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_by_nhacungcap($value) {
        $db = new dbhelper();
        $query = "SELECT * FROM LoaiSanPham WHERE nhacungcap = #nhacungcap#";
        $db->setQuery($query);
        $db->set_string_params($value);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new loaisanpham();
            $entity->id = $row['Id'];
            $entity->ten = $row['Ten'];
            $entity->nhasanxuat = $row['NhaSanXuat'];
            $entity->nhacungcap = $row['NhaCungCap'];
            $entity->mausac = $row['MauSac'];
            $entity->khohang = $row['KhoHang'];
            $entity->giaso = $row['GiaSo'];
            $entity->giachu = $row['GiaChu'];
            $entity->ghichu = $row['GhiChu'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_by_mausac($value) {
        $db = new dbhelper();
        $query = "SELECT * FROM LoaiSanPham WHERE mausac = #mausac#";
        $db->setQuery($query);
        $db->set_string_params($value);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new loaisanpham();
            $entity->id = $row['Id'];
            $entity->ten = $row['Ten'];
            $entity->nhasanxuat = $row['NhaSanXuat'];
            $entity->nhacungcap = $row['NhaCungCap'];
            $entity->mausac = $row['MauSac'];
            $entity->khohang = $row['KhoHang'];
            $entity->giaso = $row['GiaSo'];
            $entity->giachu = $row['GiaChu'];
            $entity->ghichu = $row['GhiChu'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_by_khohang($value) {
        $db = new dbhelper();
        $query = "SELECT * FROM LoaiSanPham WHERE khohang = #khohang#";
        $db->setQuery($query);
        $db->set_string_params($value);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new loaisanpham();
            $entity->id = $row['Id'];
            $entity->ten = $row['Ten'];
            $entity->nhasanxuat = $row['NhaSanXuat'];
            $entity->nhacungcap = $row['NhaCungCap'];
            $entity->mausac = $row['MauSac'];
            $entity->khohang = $row['KhoHang'];
            $entity->giaso = $row['GiaSo'];
            $entity->giachu = $row['GiaChu'];
            $entity->ghichu = $row['GhiChu'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_by_giaso($value) {
        $db = new dbhelper();
        $query = "SELECT * FROM LoaiSanPham WHERE giaso = #giaso#";
        $db->setQuery($query);
        $db->set_string_params($value);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new loaisanpham();
            $entity->id = $row['Id'];
            $entity->ten = $row['Ten'];
            $entity->nhasanxuat = $row['NhaSanXuat'];
            $entity->nhacungcap = $row['NhaCungCap'];
            $entity->mausac = $row['MauSac'];
            $entity->khohang = $row['KhoHang'];
            $entity->giaso = $row['GiaSo'];
            $entity->giachu = $row['GiaChu'];
            $entity->ghichu = $row['GhiChu'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_by_giachu($value) {
        $db = new dbhelper();
        $query = "SELECT * FROM LoaiSanPham WHERE giachu = #giachu#";
        $db->setQuery($query);
        $db->set_string_params($value);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new loaisanpham();
            $entity->id = $row['Id'];
            $entity->ten = $row['Ten'];
            $entity->nhasanxuat = $row['NhaSanXuat'];
            $entity->nhacungcap = $row['NhaCungCap'];
            $entity->mausac = $row['MauSac'];
            $entity->khohang = $row['KhoHang'];
            $entity->giaso = $row['GiaSo'];
            $entity->giachu = $row['GiaChu'];
            $entity->ghichu = $row['GhiChu'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_by_ghichu($value) {
        $db = new dbhelper();
        $query = "SELECT * FROM LoaiSanPham WHERE ghichu = #ghichu#";
        $db->setQuery($query);
        $db->set_string_params($value);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new loaisanpham();
            $entity->id = $row['Id'];
            $entity->ten = $row['Ten'];
            $entity->nhasanxuat = $row['NhaSanXuat'];
            $entity->nhacungcap = $row['NhaCungCap'];
            $entity->mausac = $row['MauSac'];
            $entity->khohang = $row['KhoHang'];
            $entity->giaso = $row['GiaSo'];
            $entity->giachu = $row['GiaChu'];
            $entity->ghichu = $row['GhiChu'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_by_isdeleted($value) {
        $db = new dbhelper();
        $query = "SELECT * FROM LoaiSanPham WHERE isdeleted = #isdeleted#";
        $db->setQuery($query);
        $db->set_string_params($value);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new loaisanpham();
            $entity->id = $row['Id'];
            $entity->ten = $row['Ten'];
            $entity->nhasanxuat = $row['NhaSanXuat'];
            $entity->nhacungcap = $row['NhaCungCap'];
            $entity->mausac = $row['MauSac'];
            $entity->khohang = $row['KhoHang'];
            $entity->giaso = $row['GiaSo'];
            $entity->giachu = $row['GiaChu'];
            $entity->ghichu = $row['GhiChu'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_post_data() {
        $entity = new loaisanpham();
        $entity->id = $_POST["id"];
        $entity->ten = $_POST["ten"];
        $entity->nhasanxuat = $_POST["nhasanxuat"];
        $entity->nhacungcap = $_POST["nhacungcap"];
        $entity->mausac = $_POST["mausac"];
        $entity->khohang = $_POST["khohang"];
        $entity->giaso = $_POST["giaso"];
        $entity->giachu = $_POST["giachu"];
        $entity->ghichu = $_POST["ghichu"];
        $entity->isdeleted = $_POST["isdeleted"];
        return $entity;
    }

    public static function search($search_key) {
        $arr = explode(" ", trim($search_key));
        $search = "";
        for ($i = 0; $i < count($arr); $i++) {
            if ($search == "") {
                $search = $search . " WHERE ";
                $search = $search . "(";
                $search = $search . "id LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || ten LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || nhasanxuat LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || nhacungcap LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || mausac LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || khohang LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || giaso LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || giachu LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || ghichu LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || isdeleted LIKE '%" . $arr[$i] . "%'";
                $search = $search . ")";
            } else {
                $search = $search . " AND ";
                $search = $search . "(";
                $search = $search . "id LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || ten LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || nhasanxuat LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || nhacungcap LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || mausac LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || khohang LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || giaso LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || giachu LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || ghichu LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || isdeleted LIKE '%" . $arr[$i] . "%'";
                $search = $search . ")";
            }
            $db = new dbhelper();
            $query = "SELECT * FROM LoaiSanPham" . $search;
            $db->setQuery($query);
            $result = $db->excute();
            $entity_arr = array();
            $index = 0;
            while ($row = mysql_fetch_array($result)) {
                $entity = new loaisanpham();
                $entity->id = $row['Id'];
                $entity->ten = $row['Ten'];
                $entity->nhasanxuat = $row['NhaSanXuat'];
                $entity->nhacungcap = $row['NhaCungCap'];
                $entity->mausac = $row['MauSac'];
                $entity->khohang = $row['KhoHang'];
                $entity->giaso = $row['GiaSo'];
                $entity->giachu = $row['GiaChu'];
                $entity->ghichu = $row['GhiChu'];
                $entity->isdeleted = $row['IsDeleted'];
                $entity_arr[$index] = $entity;
                $index = $index + 1;
            }
            return $entity_arr;
        }
    }

}

?><?

class sanpham {

    public $id;
    public $sokhung;
    public $somay;
    public $sodangkiem;
    public $tinhtrang;
    public $ghichu;
    public $isdeleted;

}

class sanphamdb {

    public static function insert(&$entity) {
        $db = new dbhelper();
        $query = "     INSERT INTO SanPham ( SoKhung , SoMay , SoDangKiem , TinhTrang , GhiChu ,  IsDeleted) VALUES ( #SoKhung#, #SoMay#, #SoDangKiem#, #TinhTrang#, #GhiChu#, #IsDeleted#)";
        $db->setQuery($query);
        $db->set_string_params("SoKhung", $entity->sokhung);
        $db->set_string_params("SoMay", $entity->somay);
        $db->set_string_params("SoDangKiem", $entity->sodangkiem);
        $db->set_string_params("TinhTrang", $entity->tinhtrang);
        $db->set_string_params("GhiChu", $entity->ghichu);
        $db->set_string_params("IsDeleted", $entity->isdeleted);
        return $db->excute();
    }

    public static function update(&$entity) {
        $db = new dbhelper();
        $query = "UPDATE SanPham SET SoKhung = #SoKhung#, SoMay = #SoMay#, SoDangKiem = #SoDangKiem#, TinhTrang = #TinhTrang#, GhiChu = #GhiChu#, IsDeleted = #IsDeleted# WHERE Id = #Id#";
        $db->setQuery($query);
        $db->set_string_params("Id", $entity->id);
        $db->set_string_params("SoKhung", $entity->sokhung);
        $db->set_string_params("SoMay", $entity->somay);
        $db->set_string_params("SoDangKiem", $entity->sodangkiem);
        $db->set_string_params("TinhTrang", $entity->tinhtrang);
        $db->set_string_params("GhiChu", $entity->ghichu);
        $db->set_string_params("IsDeleted", $entity->isdeleted);
        return $db->excute();
    }

    public static function get_all() {
        $db = new dbhelper();
        $query = "SELECT * FROM SanPham";
        $db->setQuery($query);
        $result = $db->excute();
        $entity_arr = array();
        $index = 0;
        while ($row = mysql_fetch_array($result)) {
            $entity = new sanpham();
            $entity->id = $row['Id'];
            $entity->sokhung = $row['SoKhung'];
            $entity->somay = $row['SoMay'];
            $entity->sodangkiem = $row['SoDangKiem'];
            $entity->tinhtrang = $row['TinhTrang'];
            $entity->ghichu = $row['GhiChu'];
            $entity->isdeleted = $row['IsDeleted'];
            $entity_arr[$index] = $entity;
            $index = $index + 1;
        }
        return $entity_arr;
    }

    public static function get(&$entity) {
        $db = new dbhelper();
        $query = "SELECT * FROM SanPham WHERE Id = #Id#";
        $db->setQuery($query);
        $db->set_string_params("Id", $entity->id);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new sanpham();
            $entity->id = $row['Id'];
            $entity->sokhung = $row['SoKhung'];
            $entity->somay = $row['SoMay'];
            $entity->sodangkiem = $row['SoDangKiem'];
            $entity->tinhtrang = $row['TinhTrang'];
            $entity->ghichu = $row['GhiChu'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_by_id($value) {
        $db = new dbhelper();
        $query = "SELECT * FROM SanPham WHERE id = #id#";
        $db->setQuery($query);
        $db->set_string_params($value);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new sanpham();
            $entity->id = $row['Id'];
            $entity->sokhung = $row['SoKhung'];
            $entity->somay = $row['SoMay'];
            $entity->sodangkiem = $row['SoDangKiem'];
            $entity->tinhtrang = $row['TinhTrang'];
            $entity->ghichu = $row['GhiChu'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_by_sokhung($value) {
        $db = new dbhelper();
        $query = "SELECT * FROM SanPham WHERE sokhung = #sokhung#";
        $db->setQuery($query);
        $db->set_string_params($value);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new sanpham();
            $entity->id = $row['Id'];
            $entity->sokhung = $row['SoKhung'];
            $entity->somay = $row['SoMay'];
            $entity->sodangkiem = $row['SoDangKiem'];
            $entity->tinhtrang = $row['TinhTrang'];
            $entity->ghichu = $row['GhiChu'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_by_somay($value) {
        $db = new dbhelper();
        $query = "SELECT * FROM SanPham WHERE somay = #somay#";
        $db->setQuery($query);
        $db->set_string_params($value);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new sanpham();
            $entity->id = $row['Id'];
            $entity->sokhung = $row['SoKhung'];
            $entity->somay = $row['SoMay'];
            $entity->sodangkiem = $row['SoDangKiem'];
            $entity->tinhtrang = $row['TinhTrang'];
            $entity->ghichu = $row['GhiChu'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_by_sodangkiem($value) {
        $db = new dbhelper();
        $query = "SELECT * FROM SanPham WHERE sodangkiem = #sodangkiem#";
        $db->setQuery($query);
        $db->set_string_params($value);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new sanpham();
            $entity->id = $row['Id'];
            $entity->sokhung = $row['SoKhung'];
            $entity->somay = $row['SoMay'];
            $entity->sodangkiem = $row['SoDangKiem'];
            $entity->tinhtrang = $row['TinhTrang'];
            $entity->ghichu = $row['GhiChu'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_by_tinhtrang($value) {
        $db = new dbhelper();
        $query = "SELECT * FROM SanPham WHERE tinhtrang = #tinhtrang#";
        $db->setQuery($query);
        $db->set_string_params($value);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new sanpham();
            $entity->id = $row['Id'];
            $entity->sokhung = $row['SoKhung'];
            $entity->somay = $row['SoMay'];
            $entity->sodangkiem = $row['SoDangKiem'];
            $entity->tinhtrang = $row['TinhTrang'];
            $entity->ghichu = $row['GhiChu'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_by_ghichu($value) {
        $db = new dbhelper();
        $query = "SELECT * FROM SanPham WHERE ghichu = #ghichu#";
        $db->setQuery($query);
        $db->set_string_params($value);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new sanpham();
            $entity->id = $row['Id'];
            $entity->sokhung = $row['SoKhung'];
            $entity->somay = $row['SoMay'];
            $entity->sodangkiem = $row['SoDangKiem'];
            $entity->tinhtrang = $row['TinhTrang'];
            $entity->ghichu = $row['GhiChu'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_by_isdeleted($value) {
        $db = new dbhelper();
        $query = "SELECT * FROM SanPham WHERE isdeleted = #isdeleted#";
        $db->setQuery($query);
        $db->set_string_params($value);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new sanpham();
            $entity->id = $row['Id'];
            $entity->sokhung = $row['SoKhung'];
            $entity->somay = $row['SoMay'];
            $entity->sodangkiem = $row['SoDangKiem'];
            $entity->tinhtrang = $row['TinhTrang'];
            $entity->ghichu = $row['GhiChu'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_post_data() {
        $entity = new sanpham();
        $entity->id = $_POST["id"];
        $entity->sokhung = $_POST["sokhung"];
        $entity->somay = $_POST["somay"];
        $entity->sodangkiem = $_POST["sodangkiem"];
        $entity->tinhtrang = $_POST["tinhtrang"];
        $entity->ghichu = $_POST["ghichu"];
        $entity->isdeleted = $_POST["isdeleted"];
        return $entity;
    }

    public static function search($search_key) {
        $arr = explode(" ", trim($search_key));
        $search = "";
        for ($i = 0; $i < count($arr); $i++) {
            if ($search == "") {
                $search = $search . " WHERE ";
                $search = $search . "(";
                $search = $search . "id LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || sokhung LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || somay LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || sodangkiem LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || tinhtrang LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || ghichu LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || isdeleted LIKE '%" . $arr[$i] . "%'";
                $search = $search . ")";
            } else {
                $search = $search . " AND ";
                $search = $search . "(";
                $search = $search . "id LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || sokhung LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || somay LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || sodangkiem LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || tinhtrang LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || ghichu LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || isdeleted LIKE '%" . $arr[$i] . "%'";
                $search = $search . ")";
            }
            $db = new dbhelper();
            $query = "SELECT * FROM SanPham" . $search;
            $db->setQuery($query);
            $result = $db->excute();
            $entity_arr = array();
            $index = 0;
            while ($row = mysql_fetch_array($result)) {
                $entity = new sanpham();
                $entity->id = $row['Id'];
                $entity->sokhung = $row['SoKhung'];
                $entity->somay = $row['SoMay'];
                $entity->sodangkiem = $row['SoDangKiem'];
                $entity->tinhtrang = $row['TinhTrang'];
                $entity->ghichu = $row['GhiChu'];
                $entity->isdeleted = $row['IsDeleted'];
                $entity_arr[$index] = $entity;
                $index = $index + 1;
            }
            return $entity_arr;
        }
    }

}

?><?

class taikhoan {

    public $tennguoidung;
    public $matkhau;
    public $capdo;
    public $isdeleted;

}

class taikhoandb {

    public static function insert(&$entity) {
        $db = new dbhelper();
        $query = "   INSERT INTO TaiKhoan ( TenNguoiDung , MatKhau , CapDo ,  IsDeleted) VALUES ( #TenNguoiDung#, #MatKhau#, #CapDo#, #IsDeleted#)";
        $db->setQuery($query);
        $db->set_string_params("TenNguoiDung", $entity->tennguoidung);
        $db->set_string_params("MatKhau", $entity->matkhau);
        $db->set_string_params("CapDo", $entity->capdo);
        $db->set_string_params("IsDeleted", $entity->isdeleted);
        return $db->excute();
    }

    public static function update(&$entity) {
        $db = new dbhelper();
        $query = "UPDATE TaiKhoan SET TenNguoiDung = #TenNguoiDung#, MatKhau = #MatKhau#, CapDo = #CapDo#, IsDeleted = #IsDeleted# WHERE ";
        $db->setQuery($query);
        $db->set_string_params("TenNguoiDung", $entity->tennguoidung);
        $db->set_string_params("MatKhau", $entity->matkhau);
        $db->set_string_params("CapDo", $entity->capdo);
        $db->set_string_params("IsDeleted", $entity->isdeleted);
        return $db->excute();
    }

    public static function get_all() {
        $db = new dbhelper();
        $query = "SELECT * FROM TaiKhoan";
        $db->setQuery($query);
        $result = $db->excute();
        $entity_arr = array();
        $index = 0;
        while ($row = mysql_fetch_array($result)) {
            $entity = new taikhoan();
            $entity->tennguoidung = $row['TenNguoiDung'];
            $entity->matkhau = $row['MatKhau'];
            $entity->capdo = $row['CapDo'];
            $entity->isdeleted = $row['IsDeleted'];
            $entity_arr[$index] = $entity;
            $index = $index + 1;
        }
        return $entity_arr;
    }

    public static function get(&$entity) {
        $db = new dbhelper();
        $query = "SELECT * FROM TaiKhoan WHERE TenNguoiDung = #TenNguoiDung#";
        $db->setQuery($query);
        $db->set_string_params("TenNguoiDung", $entity->tennguoidung);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new taikhoan();
            $entity->tennguoidung = $row['TenNguoiDung'];
            $entity->matkhau = $row['MatKhau'];
            $entity->capdo = $row['CapDo'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_by_tennguoidung($value) {
        $db = new dbhelper();
        $query = "SELECT * FROM TaiKhoan WHERE tennguoidung = #tennguoidung#";
        $db->setQuery($query);
        $db->set_string_params($value);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new taikhoan();
            $entity->tennguoidung = $row['TenNguoiDung'];
            $entity->matkhau = $row['MatKhau'];
            $entity->capdo = $row['CapDo'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_by_matkhau($value) {
        $db = new dbhelper();
        $query = "SELECT * FROM TaiKhoan WHERE matkhau = #matkhau#";
        $db->setQuery($query);
        $db->set_string_params($value);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new taikhoan();
            $entity->tennguoidung = $row['TenNguoiDung'];
            $entity->matkhau = $row['MatKhau'];
            $entity->capdo = $row['CapDo'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_by_capdo($value) {
        $db = new dbhelper();
        $query = "SELECT * FROM TaiKhoan WHERE capdo = #capdo#";
        $db->setQuery($query);
        $db->set_string_params($value);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new taikhoan();
            $entity->tennguoidung = $row['TenNguoiDung'];
            $entity->matkhau = $row['MatKhau'];
            $entity->capdo = $row['CapDo'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_by_isdeleted($value) {
        $db = new dbhelper();
        $query = "SELECT * FROM TaiKhoan WHERE isdeleted = #isdeleted#";
        $db->setQuery($query);
        $db->set_string_params($value);
        $result = $db->excute();
        while ($row = mysql_fetch_array($result)) {
            $entity = new taikhoan();
            $entity->tennguoidung = $row['TenNguoiDung'];
            $entity->matkhau = $row['MatKhau'];
            $entity->capdo = $row['CapDo'];
            $entity->isdeleted = $row['IsDeleted'];
            return $entity;
        }
    }

    public static function get_post_data() {
        $entity = new taikhoan();
        $entity->tennguoidung = $_POST["tennguoidung"];
        $entity->matkhau = $_POST["matkhau"];
        $entity->capdo = $_POST["capdo"];
        $entity->isdeleted = $_POST["isdeleted"];
        return $entity;
    }

    public static function search($search_key) {
        $arr = explode(" ", trim($search_key));
        $search = "";
        for ($i = 0; $i < count($arr); $i++) {
            if ($search == "") {
                $search = $search . " WHERE ";
                $search = $search . "(";
                $search = $search . "tennguoidung LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || matkhau LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || capdo LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || isdeleted LIKE '%" . $arr[$i] . "%'";
                $search = $search . ")";
            } else {
                $search = $search . " AND ";
                $search = $search . "(";
                $search = $search . "tennguoidung LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || matkhau LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || capdo LIKE '%" . $arr[$i] . "%'";
                $search = $search . " || isdeleted LIKE '%" . $arr[$i] . "%'";
                $search = $search . ")";
            }
            $db = new dbhelper();
            $query = "SELECT * FROM TaiKhoan" . $search;
            $db->setQuery($query);
            $result = $db->excute();
            $entity_arr = array();
            $index = 0;
            while ($row = mysql_fetch_array($result)) {
                $entity = new taikhoan();
                $entity->tennguoidung = $row['TenNguoiDung'];
                $entity->matkhau = $row['MatKhau'];
                $entity->capdo = $row['CapDo'];
                $entity->isdeleted = $row['IsDeleted'];
                $entity_arr[$index] = $entity;
                $index = $index + 1;
            }
            return $entity_arr;
        }
    }

}

?>